From 4a3ae0229edb6f87b8988352b99f6e5c9b383a23 Mon Sep 17 00:00:00 2001 From: Parikshith Mohite Date: Tue, 10 Sep 2024 13:50:38 -0400 Subject: [PATCH] Cleans up some logic --- src/components/DynamicRecommendations.tsx | 28 +++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/components/DynamicRecommendations.tsx b/src/components/DynamicRecommendations.tsx index 28ac8d6..7e0785a 100644 --- a/src/components/DynamicRecommendations.tsx +++ b/src/components/DynamicRecommendations.tsx @@ -74,22 +74,26 @@ class DynamicRecommendations extends React.Component<{}, {songQueue: Array { + shouldArtistQueueBeUpdated = (): boolean => { if (!Spicetify.Player.data.item.artists) { - return; + return false; + } + if (!this.state.artistQueue) { + return true; } - let cont = false; - if (this.state.artistQueue) { - for (const artist of Spicetify.Player.data.item.artists) { - let fromIndex = this.state.artistQueue.length >= Spicetify.Player.data.item.artists.length ? this.state.artistQueue.length - Spicetify.Player.data.item.artists.length : 0; - if (!this.state.artistQueue.includes(getID(artist.uri), fromIndex)) { - cont = true; - break; - }; - } + for (const artist of Spicetify.Player.data.item.artists) { + let fromIndex = Math.max(0, this.state.artistQueue.length - Spicetify.Player.data.item.artists.length); + if (!this.state.artistQueue.includes(getID(artist.uri), fromIndex)) { + return true; + }; } - if (!cont) { + + return false; + }; + + setArtistQueue = () => { + if (!Spicetify.Player.data.item.artists || !this.shouldArtistQueueBeUpdated()) { return; }