fix: background offline interval

This commit is contained in:
David Ralph
2021-08-01 18:20:38 +01:00
parent 141da4ba36
commit 1ce6cb9419
2 changed files with 21 additions and 3 deletions

View File

@@ -56,13 +56,16 @@ export default class Background extends React.PureComponent {
Math.floor(Math.random() * offlineImages[photographer].photo.length)
];
this.setState({
const object = {
url: `./offline-images/${randomImage}.webp`,
photoInfo: {
offline: true,
credit: photographer
}
});
}
this.setState(object);
localStorage.setItem('currentBackground', JSON.stringify(object));
}
setBackground() {
@@ -361,7 +364,20 @@ export default class Background extends React.PureComponent {
}, Number(interval), 'background');
try {
this.setState(JSON.parse(localStorage.getItem('currentBackground')));
// todo: refactor this mess
const current = JSON.parse(localStorage.getItem('currentBackground'));
const offline = localStorage.getItem('offlineMode')
if (current.url.startsWith('http') && offline === 'false') {
this.setState(current);
} else if (current.url.startsWith('http')) {
this.offlineBackground();
} else {
if (offline === 'false') {
localStorage.removeItem('currentBackground');
return this.getBackground();
}
this.setState(current);
}
} catch (e) {
this.setBackground();
}