From 822a8ff627e299797fdbb67e0f12c1a709cb2ad8 Mon Sep 17 00:00:00 2001 From: Isaac Date: Mon, 21 Nov 2022 17:30:22 +0000 Subject: [PATCH] fix: don't get the same image twice in a row --- src/components/widgets/background/Background.jsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/components/widgets/background/Background.jsx b/src/components/widgets/background/Background.jsx index 3d618951..89bb3f73 100644 --- a/src/components/widgets/background/Background.jsx +++ b/src/components/widgets/background/Background.jsx @@ -83,7 +83,7 @@ export default class Background extends PureComponent { } } - async getAPIImageData() { + async getAPIImageData(currentPun) { let apiCategories; try { @@ -98,8 +98,8 @@ export default class Background extends PureComponent { if (!Array.isArray(backgroundExclude)) { backgroundExclude = []; } - if (this.state.photoInfo.pun) { - backgroundExclude.push(this.state.photoInfo.pun) + if (currentPun) { + backgroundExclude.push(currentPun) } let requestURL, data; @@ -195,13 +195,12 @@ export default class Background extends PureComponent { } // API background - let data = JSON.parse(localStorage.getItem('nextImage')) || await this.getAPIImageData(); localStorage.setItem('nextImage', null); if (data) { this.setState(data); localStorage.setItem('currentBackground', JSON.stringify(data)); - localStorage.setItem('nextImage', JSON.stringify(await this.getAPIImageData())); // pre-fetch data about the next image + localStorage.setItem('nextImage', JSON.stringify(await this.getAPIImageData(data.photoInfo.pun))); // pre-fetch data about the next image } break;