From 5e3b7b4b39315d72ba8843b465bb49986ec40ae4 Mon Sep 17 00:00:00 2001 From: dinotutic Date: Mon, 28 Nov 2022 02:08:16 +0100 Subject: [PATCH] fixed the search and saveToPlaylist functions --- .vscode/launch.json | 15 +++++++++++++++ src/Components/SearchBar/SearchBar.js | 4 +++- src/util/Spotify.js | 11 +++++------ 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..28b0da3 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "chrome", + "request": "launch", + "name": "Launch Chrome", + "url": "http://localhost:3000", + "webRoot": "${workspaceFolder}" + } + ] +} diff --git a/src/Components/SearchBar/SearchBar.js b/src/Components/SearchBar/SearchBar.js index a50842a..d29ac19 100644 --- a/src/Components/SearchBar/SearchBar.js +++ b/src/Components/SearchBar/SearchBar.js @@ -22,7 +22,9 @@ class SearchBar extends React.Component { placeholder="Enter A Song, Album, or Artist" onChange={this.handleTermChange} /> - + ); } diff --git a/src/util/Spotify.js b/src/util/Spotify.js index 0975b98..d6c1185 100644 --- a/src/util/Spotify.js +++ b/src/util/Spotify.js @@ -1,5 +1,5 @@ const clientId = "c39c93bbf05745fb986d1e566004eb31"; -const redirectUri = "http://localhost:3000/"; +const redirectUri = "http://localhost:3000"; let accessToken = ""; export const Spotify = { @@ -22,8 +22,7 @@ export const Spotify = { window.history.pushState("Access Token", null, "/"); return accessToken; } else { - const accessUrl = `https://accounts.spotify.com/authorize?client_id=${clientId}&response_type= - token&scope=playlist-modify-public&redirect_uri=${redirectUri}`; + const accessUrl = `https://accounts.spotify.com/authorize?client_id=${clientId}&response_type=token&scope=playlist-modify-public&redirect_uri=${redirectUri}`; window.location = accessUrl; } }, @@ -54,13 +53,13 @@ export const Spotify = { if (!name || !trackUris.length) { return; } - const accessToken = Spotify.getAccessToken; + const accessToken = Spotify.getAccessToken(); const headers = { Authorization: `Bearer ${accessToken}` }; let userId; return fetch(`https://api.spotify.com/v1/me`, { headers: headers }) .then((response) => response.json()) .then((jsonResponse) => { - userId = jsonResponse.Id; + userId = jsonResponse.id; return fetch(`https://api.spotify.com/v1/users/${userId}/playlists`, { headers: headers, method: "POST", @@ -68,7 +67,7 @@ export const Spotify = { }) .then((response) => response.json()) .then((jsonResponse) => { - const playlistId = jsonResponse.Id; + const playlistId = jsonResponse.id; return fetch( `https:/api.spotify.com/v1/users/${userId}/playlists/${playlistId}/tracks`, {