fix: background refresh spam effects issue

This commit is contained in:
David Ralph
2022-09-07 11:22:00 +01:00
parent 532f7cff8c
commit b364923738
2 changed files with 6 additions and 7 deletions

View File

@@ -6,7 +6,6 @@ import { PureComponent } from 'react';
import PhotoInformation from './PhotoInformation';
import EventBus from 'modules/helpers/eventbus';
import Interval from 'modules/helpers/interval';
import {
videoCheck,
offlineBackground,
@@ -92,7 +91,6 @@ export default class Background extends PureComponent {
}
const setFavourited = ({ type, url, credit, location, camera }) => {
console.log(type);
if (type === 'random_colour' || type === 'random_gradient') {
return this.setState({
type: 'colour',
@@ -118,7 +116,7 @@ export default class Background extends PureComponent {
switch (type) {
case 'api':
if (offline) {
return this.setState(offlineBackground());
return this.setState(offlineBackground('api'));
}
// API background
@@ -145,7 +143,7 @@ export default class Background extends PureComponent {
data = await (await fetch(requestURL)).json();
} catch (e) {
// if requesting to the API fails, we get an offline image
return this.setState(offlineBackground());
return this.setState(offlineBackground('api'));
}
let photoURL, photographerURL;
@@ -210,7 +208,7 @@ export default class Background extends PureComponent {
// allow users to use offline images
if (offline && !customBackground.startsWith('data:')) {
return this.setState(offlineBackground());
return this.setState(offlineBackground('custom'));
}
if (
@@ -235,7 +233,7 @@ export default class Background extends PureComponent {
case 'photo_pack':
if (offline) {
return this.setState(offlineBackground());
return this.setState(offlineBackground('photo_pack'));
}
const photofavourited = JSON.parse(localStorage.getItem('favourite'));

View File

@@ -9,7 +9,7 @@ export function videoCheck(url) {
);
}
export function offlineBackground() {
export function offlineBackground(type) {
// Get all photographers from the keys in offlineImages.json
const photographers = Object.keys(offlineImages);
const photographer = photographers[Math.floor(Math.random() * photographers.length)];
@@ -21,6 +21,7 @@ export function offlineBackground() {
const object = {
url: `./offline-images/${randomImage}.webp`,
type,
photoInfo: {
offline: true,
credit: photographer,