From 0db25024981419bbc3a9b9e4b9dea87d721ad2ca Mon Sep 17 00:00:00 2001 From: alexsparkes Date: Thu, 27 Oct 2022 20:24:08 +0100 Subject: [PATCH] fix: numerous background interval fixes --- .../helpers/sharemodal/ShareModal.jsx | 2 +- .../modals/main/settings/sections/Quote.jsx | 3 + .../widgets/background/Background.jsx | 64 ++++++++++++++----- 3 files changed, 53 insertions(+), 16 deletions(-) diff --git a/src/components/helpers/sharemodal/ShareModal.jsx b/src/components/helpers/sharemodal/ShareModal.jsx index 122f40a5..398332ba 100644 --- a/src/components/helpers/sharemodal/ShareModal.jsx +++ b/src/components/helpers/sharemodal/ShareModal.jsx @@ -9,7 +9,7 @@ import { toast } from 'react-toastify'; import './sharemodal.scss'; export default function ShareModal({ modalClose, data }) { - const url = variables.constants.MARKETPLACE_URL + '/share/' + btoa(data.api_name); + const url = variables.constants.MARKETPLACE_URL + '/share/' + (btoa(data.api_name) || ''); const copyLink = () => { navigator.clipboard.writeText(data); diff --git a/src/components/modals/main/settings/sections/Quote.jsx b/src/components/modals/main/settings/sections/Quote.jsx index 77f41786..fb729cdb 100644 --- a/src/components/modals/main/settings/sections/Quote.jsx +++ b/src/components/modals/main/settings/sections/Quote.jsx @@ -259,6 +259,9 @@ export default class QuoteSettings extends PureComponent { value2={Date.now()} > + diff --git a/src/components/widgets/background/Background.jsx b/src/components/widgets/background/Background.jsx index 5ddc59e1..ff8599e6 100644 --- a/src/components/widgets/background/Background.jsx +++ b/src/components/widgets/background/Background.jsx @@ -250,16 +250,53 @@ export default class Background extends PureComponent { } }); if (photoPack) { - const randomPhoto = photoPack[Math.floor(Math.random() * photoPack.length)]; - return this.setState({ - url: randomPhoto.url.default, - type: 'photo_pack', - photoInfo: { - hidden: false, - credit: randomPhoto.photographer, - location: randomPhoto.location || 'N/A', - }, - }); + const randomNumber = Math.floor(Math.random() * photoPack.length) + const randomPhoto = photoPack[randomNumber]; + if ( + localStorage.getItem('backgroundchange') === 'refresh' || + localStorage.getItem('backgroundchange') === null + ) { + localStorage.setItem('marketplaceNumber', randomNumber) + return this.setState({ + url: randomPhoto.url.default, + type: 'photo_pack', + photoInfo: { + hidden: false, + credit: randomPhoto.photographer, + location: randomPhoto.location || 'N/A', + }, + }); + } else { + if ( + Number( + Number(localStorage.getItem('backgroundStartTime')) + + Number(localStorage.getItem('backgroundchange')) >= + Number(Date.now()), + ) + ) { + const randomPhoto = photoPack[localStorage.getItem('marketplaceNumber')]; + return this.setState({ + url: randomPhoto.url.default, + type: 'photo_pack', + photoInfo: { + hidden: false, + credit: randomPhoto.photographer, + location: randomPhoto.location || 'N/A', + }, + }); + } else { + localStorage.setItem('marketplaceNumber', randomNumber) + return this.setState({ + url: randomPhoto.url.default, + type: 'photo_pack', + photoInfo: { + hidden: false, + credit: randomPhoto.photographer, + location: randomPhoto.location || 'N/A', + }, + }); + } + } } break; default: @@ -384,7 +421,7 @@ export default class Background extends PureComponent { if ( localStorage.getItem('backgroundchange') === 'refresh' || - localStorage.getItem('quotechange') === null + localStorage.getItem('backgroundchange') === null ) { try { document.getElementById('backgroundImage').classList.remove('fade-in'); @@ -399,10 +436,7 @@ export default class Background extends PureComponent { const test = localStorage.getItem('backgroundchange'); this.interval = setInterval(() => { - const targetTime = Number( - Number(localStorage.getItem('backgroundStartTime')) + - Number(test), - ); + const targetTime = Number(Number(localStorage.getItem('backgroundStartTime')) + Number(test)); const currentTime = Number(Date.now()); const type = localStorage.getItem('backgroundType');