Work more on settings and update modal etc

Co-authored-by: Alex Sparkes <turbomarshmello@gmail.com>
Co-authored-by: Wessel Tip <discord@go2it.eu>
This commit is contained in:
David Ralph
2020-07-16 17:40:24 +01:00
parent d9a4c76a8e
commit f458a69781
14 changed files with 299 additions and 121 deletions

View File

@@ -7,38 +7,22 @@ export default class Background extends React.Component {
doOffline() {
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
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;
}
case 1: {
photographer = 'Tirachard Kumtanom';
break;
}
case 4: {
photographer = 'Sohail Na';
break;
}
case 7: {
photographer = 'Miriam Espacio';
break;
}
case 10: {
photographer = 'NO NAME';
break;
}
case 20: {
photographer = 'Fabian Wiktor';
break;
}
case 1: photographer = 'Tirachard Kumtanom'; break;
case 4: photographer = 'Sohail Na'; break;
case 7: photographer = 'Miriam Espacio'; break;
case 10: photographer = 'NO NAME'; break;
case 20: photographer = 'Fabian Wiktor'; break;
default: photographer = 'Unknown'; break;
}
document.getElementById('photographer').innerText = `Photo by ${photographer} (Pexels)`; // Set the credit
document.getElementById('root').style.backgroundImage = `url(../offline-images/${photo}.jpeg)`; // Set the background
}
document.getElementById('backgroundImage').style.backgroundImage = `url(../offline-images/${photo}.jpeg)`; // Set the background
}
async setBackground() {
const enabled = localStorage.getItem('offlineMode');
@@ -46,12 +30,13 @@ export default class Background extends React.Component {
try { // First we try and get an image from the API...
let requestURL;
if (await supportsWebP) requestURL = 'https://api.muetab.xyz/getImage?webp=true';
const enabled = localStorage.getItem('webp');
if (await supportsWebP && enabled === 'true') requestURL = 'https://api.muetab.xyz/getImage?webp=true';
else requestURL = 'https://api.muetab.xyz/getImage?category=Outdoors';
let data = await fetch(requestURL);
data = await data.json();
document.getElementById('root').style.backgroundImage = `url(${data.file})`; // Set the background
document.getElementById('backgroundImage').style.backgroundImage = `url(${data.file})`; // Set the background
document.getElementById('photographer').innerText = `Photo by ${data.photographer}`; // Set the credit
document.getElementById('location').innerText = `${data.location}`; // Set the location tooltip
} catch (e) { // ..and if that fails we load one locally