mirror of
https://github.com/mue/mue.git
synced 2026-07-25 09:47:26 +02:00
Optimise the code and add a test for something
This commit is contained in:
@@ -14,7 +14,9 @@ export default class Background extends React.Component {
|
|||||||
const photo = Math.floor(Math.random() * (20 - 1 + 1)) + 1; // There are 20 images in the offline-images folder
|
const photo = Math.floor(Math.random() * (20 - 1 + 1)) + 1; // There are 20 images in the offline-images folder
|
||||||
document.getElementById('backgroundCredits').style.display = 'none'; // Hide the location icon
|
document.getElementById('backgroundCredits').style.display = 'none'; // Hide the location icon
|
||||||
let photographer; // Photographer credit
|
let photographer; // Photographer credit
|
||||||
switch (photo) { // Select photographer based on image file number
|
let pixabayNumbers = [2, 3, 9, 11, 13, 14, 15]; // As there are a lot of Pixabay photos, we shorten the code a bit here
|
||||||
|
if (pixabayNumbers.includes(photo)) photographer = 'Pixabay';
|
||||||
|
else switch (photo) {
|
||||||
default: {
|
default: {
|
||||||
photographer = 'Unknown';
|
photographer = 'Unknown';
|
||||||
break;
|
break;
|
||||||
@@ -23,14 +25,6 @@ export default class Background extends React.Component {
|
|||||||
photographer = 'Tirachard Kumtanom';
|
photographer = 'Tirachard Kumtanom';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2: {
|
|
||||||
photographer = 'Pixabay';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 3: {
|
|
||||||
photographer = 'Pixabay';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 4: {
|
case 4: {
|
||||||
photographer = 'Sohail Na';
|
photographer = 'Sohail Na';
|
||||||
break;
|
break;
|
||||||
@@ -39,30 +33,10 @@ export default class Background extends React.Component {
|
|||||||
photographer = 'Miriam Espacio';
|
photographer = 'Miriam Espacio';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 9: {
|
|
||||||
photographer = 'Pixabay';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 10: {
|
case 10: {
|
||||||
photographer = 'NO NAME';
|
photographer = 'NO NAME';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 11: {
|
|
||||||
photographer = 'Pixabay';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 13: {
|
|
||||||
photographer = 'Pixabay';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 14: {
|
|
||||||
photographer = 'Pixabay';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 15: {
|
|
||||||
photographer = 'Pixabay';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 20: {
|
case 20: {
|
||||||
photographer = 'Fabian Wiktor';
|
photographer = 'Fabian Wiktor';
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -15,6 +15,13 @@ export default class Quote extends React.Component {
|
|||||||
try { // First we try and get a quote from the API...
|
try { // First we try and get a quote from the API...
|
||||||
let data = await fetch('https://api.muetab.xyz/getQuote');
|
let data = await fetch('https://api.muetab.xyz/getQuote');
|
||||||
data = await data.json();
|
data = await data.json();
|
||||||
|
if (data.statusCode === 429) { // If we hit the ratelimit, we fallback to local quotes
|
||||||
|
const quote = Quotes.random(); // Get a random quote from our local package
|
||||||
|
return this.setState({
|
||||||
|
quote: quote.quote,
|
||||||
|
author: quote.author
|
||||||
|
}); // Set the quote
|
||||||
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
quote: data.quote,
|
quote: data.quote,
|
||||||
author: data.author
|
author: data.author
|
||||||
|
|||||||
Reference in New Issue
Block a user