From 57445a54deb01afa1aa9d4090b5d13f6dc332997 Mon Sep 17 00:00:00 2001 From: Parikshith Mohite Date: Tue, 1 Oct 2024 17:00:31 -0400 Subject: [PATCH] Update comments --- src/components/NowPlaying.tsx | 5 ++++- src/components/RecommendationsModal.tsx | 4 +--- src/services/enhancifyInternalService.tsx | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/NowPlaying.tsx b/src/components/NowPlaying.tsx index 5468723..48c42ff 100644 --- a/src/components/NowPlaying.tsx +++ b/src/components/NowPlaying.tsx @@ -23,7 +23,7 @@ class NowPlaying extends React.Component<{}, {audioFeatures: AudioFeaturesRespon songMetrics: [], // Current song metric information metricsToDisplay: Spicetify.LocalStorage.get("metricsToDisplay") != "" ? Spicetify.LocalStorage.get("metricsToDisplay")?.split(',') || ["Danceability", "Energy", "Acousticness", "Loudness", "Key", "Tempo"] : [], // Current metric information types modalIsOpen: false, // Whether the modal is currently open - selectedMetrics: JSON.parse(Spicetify.LocalStorage.get("selectedMetrics") || "{}"), + selectedMetrics: JSON.parse(Spicetify.LocalStorage.get("selectedMetrics") || "{}"), // Metrics that have been selected to be fed into the Spotify recommendations endpoint } componentDidMount = () => { @@ -78,6 +78,7 @@ class NowPlaying extends React.Component<{}, {audioFeatures: AudioFeaturesRespon if (newArray.includes(metric)) { newArray = newArray.filter((val) => val != metric); + // If a metric is being hidden from the display, it should not be fed into the recommendations endpoint if (metric in this.state.selectedMetrics) { let copy: SelectedMetrics = { ...this.state.selectedMetrics }; delete copy[metric]; @@ -98,12 +99,14 @@ class NowPlaying extends React.Component<{}, {audioFeatures: AudioFeaturesRespon }, this.setSongMetrics); } + // Set whether the modal should be open or closed setModalIsOpen = (value: boolean) => { this.setState({ modalIsOpen: value }); } + // Select a metric to toggle whether they should be included in the recommendations endpoint request or not selectMetric = (metric: string, value: string) => { let copy: SelectedMetrics = { ...this.state.selectedMetrics }; if (metric in copy) { diff --git a/src/components/RecommendationsModal.tsx b/src/components/RecommendationsModal.tsx index f99f9c5..26292b8 100644 --- a/src/components/RecommendationsModal.tsx +++ b/src/components/RecommendationsModal.tsx @@ -10,7 +10,7 @@ import { RecommendationsRender } from "../services/enhancifyInternalService"; class RecommendationsModal extends React.Component<{modalIsOpen: boolean, setModalIsOpen: (value: boolean) => void, songURI: string, selectedMetrics: SelectedMetrics}, {recommendations: GetRecommendationsResponse | {}}> { state = { - recommendations: {} + recommendations: {} // Recommendations that show up in the modal view }; componentDidMount = () => { @@ -41,8 +41,6 @@ class RecommendationsModal extends React.Component<{modalIsOpen: boolean, setMod return ( this.props.setModalIsOpen(false)}> - {JSON.stringify(JSON.parse(Spicetify.LocalStorage.get("selectedMetrics") || "{}") as SelectedMetrics)} - {JSON.stringify(this.props.selectedMetrics)} {RecommendationsRender(this.state.recommendations)} ); diff --git a/src/services/enhancifyInternalService.tsx b/src/services/enhancifyInternalService.tsx index fd19150..5a0f1c6 100644 --- a/src/services/enhancifyInternalService.tsx +++ b/src/services/enhancifyInternalService.tsx @@ -3,6 +3,7 @@ import RecommendedTrack from "../components/RecommendedTrack"; import { Labels, MetricFeatures, SongMetricData } from "../types/enhancify"; import { AudioFeaturesResponse, GetRecommendationsResponse } from "../types/spotify-web-api"; +// Creates the recommended track view for any response from the Spotify recommendations endpoint export function RecommendationsRender(recommendations : GetRecommendationsResponse | {}) { if (Object.keys(recommendations).length == 0) { return;