mirror of
https://github.com/mue/mue.git
synced 2026-06-10 18:48:32 +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
|
||||
document.getElementById('backgroundCredits').style.display = 'none'; // Hide the location icon
|
||||
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: {
|
||||
photographer = 'Unknown';
|
||||
break;
|
||||
@@ -23,14 +25,6 @@ export default class Background extends React.Component {
|
||||
photographer = 'Tirachard Kumtanom';
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
photographer = 'Pixabay';
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
photographer = 'Pixabay';
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
photographer = 'Sohail Na';
|
||||
break;
|
||||
@@ -39,30 +33,10 @@ export default class Background extends React.Component {
|
||||
photographer = 'Miriam Espacio';
|
||||
break;
|
||||
}
|
||||
case 9: {
|
||||
photographer = 'Pixabay';
|
||||
break;
|
||||
}
|
||||
case 10: {
|
||||
photographer = 'NO NAME';
|
||||
break;
|
||||
}
|
||||
case 11: {
|
||||
photographer = 'Pixabay';
|
||||
break;
|
||||
}
|
||||
case 13: {
|
||||
photographer = 'Pixabay';
|
||||
break;
|
||||
}
|
||||
case 14: {
|
||||
photographer = 'Pixabay';
|
||||
break;
|
||||
}
|
||||
case 15: {
|
||||
photographer = 'Pixabay';
|
||||
break;
|
||||
}
|
||||
case 20: {
|
||||
photographer = 'Fabian Wiktor';
|
||||
break;
|
||||
|
||||
@@ -15,6 +15,13 @@ export default class Quote extends React.Component {
|
||||
try { // First we try and get a quote from the API...
|
||||
let data = await fetch('https://api.muetab.xyz/getQuote');
|
||||
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({
|
||||
quote: data.quote,
|
||||
author: data.author
|
||||
|
||||
Reference in New Issue
Block a user