Skip to content

Commit

Permalink
Update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
skycube19 committed Oct 1, 2024
1 parent 8e64cac commit 57445a5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/components/NowPlaying.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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];
Expand All @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions src/components/RecommendationsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -41,8 +41,6 @@ class RecommendationsModal extends React.Component<{modalIsOpen: boolean, setMod
return (
<Modal className={styles.modal} isOpen={this.props.modalIsOpen} onRequestClose={() => this.props.setModalIsOpen(false)}>
<button onClick={() => this.props.setModalIsOpen(false)}>close</button>
{JSON.stringify(JSON.parse(Spicetify.LocalStorage.get("selectedMetrics") || "{}") as SelectedMetrics)}
{JSON.stringify(this.props.selectedMetrics)}
{RecommendationsRender(this.state.recommendations)}
</Modal>
);
Expand Down
1 change: 1 addition & 0 deletions src/services/enhancifyInternalService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 57445a5

Please sign in to comment.