Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
fddf1ed6b1 | ||
d2bcd32dd2 | |||
5e3b7b4b39 | |||
5e570ffa50 |
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal file
@ -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}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -13,7 +13,7 @@
|
|||||||
"@testing-library/user-event": "^13.5.0",
|
"@testing-library/user-event": "^13.5.0",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "^5.0.1",
|
||||||
"web-vitals": "^2.1.4"
|
"web-vitals": "^2.1.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
"@testing-library/user-event": "^13.5.0",
|
"@testing-library/user-event": "^13.5.0",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-scripts": "5.0.1",
|
"react-scripts": "^5.0.1",
|
||||||
"web-vitals": "^2.1.4"
|
"web-vitals": "^2.1.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -15,14 +15,23 @@ class SearchBar extends React.Component {
|
|||||||
handleTermChange = (event) => {
|
handleTermChange = (event) => {
|
||||||
this.setState({ term: event.target.value });
|
this.setState({ term: event.target.value });
|
||||||
};
|
};
|
||||||
|
handleKeyDown = event => {
|
||||||
|
if (event.key === "Enter"){
|
||||||
|
this.search()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="SearchBar">
|
<div className="SearchBar">
|
||||||
<input
|
<input
|
||||||
placeholder="Enter A Song, Album, or Artist"
|
placeholder="Enter A Song, Album, or Artist"
|
||||||
onChange={this.handleTermChange}
|
onChange={this.handleTermChange}
|
||||||
|
onKeyDown={this.handleKeyDown}
|
||||||
/>
|
/>
|
||||||
<button className="SearchButton">SEARCH</button>
|
<button className="SearchButton" onClick={this.search}>
|
||||||
|
SEARCH
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
const clientId = "c39c93bbf05745fb986d1e566004eb31";
|
const clientId = "c39c93bbf05745fb986d1e566004eb31";
|
||||||
const redirectUri = "http://localhost:3000/";
|
// Hosted on https://jammingcademy.surge.sh/, but save playlist does not work
|
||||||
|
const redirectUri = "http://localhost:3000";
|
||||||
let accessToken = "";
|
let accessToken = "";
|
||||||
|
|
||||||
export const Spotify = {
|
export const Spotify = {
|
||||||
@ -22,8 +23,7 @@ export const Spotify = {
|
|||||||
window.history.pushState("Access Token", null, "/");
|
window.history.pushState("Access Token", null, "/");
|
||||||
return accessToken;
|
return accessToken;
|
||||||
} else {
|
} else {
|
||||||
const accessUrl = `https://accounts.spotify.com/authorize?client_id=${clientId}&response_type=
|
const accessUrl = `https://accounts.spotify.com/authorize?client_id=${clientId}&response_type=token&scope=playlist-modify-public&redirect_uri=${redirectUri}`;
|
||||||
token&scope=playlist-modify-public&redirect_uri=${redirectUri}`;
|
|
||||||
window.location = accessUrl;
|
window.location = accessUrl;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -54,13 +54,13 @@ export const Spotify = {
|
|||||||
if (!name || !trackUris.length) {
|
if (!name || !trackUris.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const accessToken = Spotify.getAccessToken;
|
const accessToken = Spotify.getAccessToken();
|
||||||
const headers = { Authorization: `Bearer ${accessToken}` };
|
const headers = { Authorization: `Bearer ${accessToken}` };
|
||||||
let userId;
|
let userId;
|
||||||
return fetch(`https://api.spotify.com/v1/me`, { headers: headers })
|
return fetch(`https://api.spotify.com/v1/me`, { headers: headers })
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((jsonResponse) => {
|
.then((jsonResponse) => {
|
||||||
userId = jsonResponse.Id;
|
userId = jsonResponse.id;
|
||||||
return fetch(`https://api.spotify.com/v1/users/${userId}/playlists`, {
|
return fetch(`https://api.spotify.com/v1/users/${userId}/playlists`, {
|
||||||
headers: headers,
|
headers: headers,
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -68,7 +68,7 @@ export const Spotify = {
|
|||||||
})
|
})
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((jsonResponse) => {
|
.then((jsonResponse) => {
|
||||||
const playlistId = jsonResponse.Id;
|
const playlistId = jsonResponse.id;
|
||||||
return fetch(
|
return fetch(
|
||||||
`https:/api.spotify.com/v1/users/${userId}/playlists/${playlistId}/tracks`,
|
`https:/api.spotify.com/v1/users/${userId}/playlists/${playlistId}/tracks`,
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user