From 4c00f56251135bc550a26061fc081c1441dd934c Mon Sep 17 00:00:00 2001 From: Sam Bao Date: Wed, 17 Jul 2024 22:28:39 -0600 Subject: [PATCH] switch over to using azure function as backend --- src/BaseInput.js | 2 +- src/FetchArtist.js | 4 +- src/GetSpotifyPlaylistArtistsWithShows.js | 2 +- src/YourFavoriteSpotifyArtists.js | 114 ---------------------- 4 files changed, 4 insertions(+), 118 deletions(-) delete mode 100644 src/YourFavoriteSpotifyArtists.js diff --git a/src/BaseInput.js b/src/BaseInput.js index b3b298f..e12d5e8 100644 --- a/src/BaseInput.js +++ b/src/BaseInput.js @@ -146,7 +146,7 @@ const BaseInput = forwardRef(({ setConcerts, let incomingArtistName = incomingArtistInfo.name; let incomingArtistId = incomingArtistInfo.id try { - let res = await fetch(`${process.env.REACT_APP_BACKEND}/FindArtistWithGigs/GetGigsById`, { + let res = await fetch(`${process.env.REACT_APP_BACKEND}/GetGigsByArtistId`, { method: "POST", headers: { "content-type": "application/json;charset=utf-8", diff --git a/src/FetchArtist.js b/src/FetchArtist.js index c229d2f..a71852a 100644 --- a/src/FetchArtist.js +++ b/src/FetchArtist.js @@ -1,6 +1,6 @@ export const FetchArtist = async (artistName) => { const response = await fetch( - `${process.env.REACT_APP_BACKEND}/FindArtistWithGigs/GetArtistsByName?artistName=${artistName}`, + `${process.env.REACT_APP_BACKEND}/GetArtistsByName/${artistName}`, { method: "GET", headers: { @@ -13,7 +13,7 @@ export const FetchArtist = async (artistName) => { let resJson = await response.json(); console.log(`artist count: ${resJson.length}`); resJson = resJson.filter((value) => value.images.length > 0); - console.log(`artist count: ${resJson.length}`); + console.log(`artist count after removing artists with no profile picture: ${resJson.length}`); return resJson; } return; diff --git a/src/GetSpotifyPlaylistArtistsWithShows.js b/src/GetSpotifyPlaylistArtistsWithShows.js index 7433e0e..d8919eb 100644 --- a/src/GetSpotifyPlaylistArtistsWithShows.js +++ b/src/GetSpotifyPlaylistArtistsWithShows.js @@ -12,7 +12,7 @@ function GetSpotifyPlaylistArtistsWithShows({followedArtists, setFollowedArtists const extractedPlaylistId = url.substring(startIndex, endIndex); setIsRequestTriggered(true); - await fetch(`${process.env.REACT_APP_BACKEND}/FindArtistWithGigs/GetSpotifyPlaylistArtistsWithGigs`, { + await fetch(`${process.env.REACT_APP_BACKEND}/GetSpotifyPlaylistArtistsWithGigs`, { method: 'POST', headers: { 'content-type': 'application/json;charset=utf-8' diff --git a/src/YourFavoriteSpotifyArtists.js b/src/YourFavoriteSpotifyArtists.js deleted file mode 100644 index b4278fa..0000000 --- a/src/YourFavoriteSpotifyArtists.js +++ /dev/null @@ -1,114 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import { Grid, Button } from '@mui/material'; -import { useLocation } from "react-router-dom"; - -function YourFavoriteSpotifyArtists({ startDate, endDate, followedArtists, setFollowedArtists }) { - let location = useLocation(); - let searchParams = new URLSearchParams(location.search); - const [code, setCode] = useState(""); - const [codeVerifier, setCodeVerifier] = useState(""); - const [disableButton, setDisableButton] = useState(false); - - useEffect(() => { - async function fetchAccessData() { - - await fetch(`${process.env.REACT_APP_BACKEND}/Authorization`, { - method: 'POST', - headers: { - 'content-type': 'application/json;charset=utf-8' - }, - body: JSON.stringify({ - ClientId: process.env.REACT_APP_SPOTIFY_CLIENTID, - Code: code, - CodeVerifier: codeVerifier, - RedirectUri: process.env.REACT_APP_REDIRECT_URL - }), - }).then(async (res) => { - console.log(`response status code: ${res.status}`); - if (res.status === 200) { - let resJson = await res.json(); - - localStorage.setItem("access_token", resJson.accessToken); - localStorage.setItem("token_type", resJson.tokenType); - localStorage.setItem("expires_in", resJson.expiresIn); - //bad practice, need to find a better way to store this - localStorage.setItem("refresh_token", resJson.refreshToken); - localStorage.setItem("scope", resJson.scope); - localStorage.setItem("created_at", resJson.createdAt) - } - return; - }).catch((err) => { - console.log("Some error occured"); - console.log(err); - }); - } - setCode(searchParams.get("code")); - setCodeVerifier(localStorage.getItem('code_verifier')) - - if (code !== null && codeVerifier !== null) { - fetchAccessData(); - } - }, [code, codeVerifier]) - - - let getSpotifyArtist = async () => { - //get access token - var access_token = localStorage.getItem("access_token"); - if (access_token !== null) { - setDisableButton(true); - //call setFollowedArtists - await fetch(`${process.env.REACT_APP_BACKEND}/FindArtistWithGigs/GetTopArtistsWithGigs`, { - method: 'POST', - headers: { - 'content-type': 'application/json;charset=utf-8' - }, - body: JSON.stringify({ - access_token: { - AccessToken: localStorage.getItem("access_token"), - TokenType: localStorage.getItem("token_type"), - ExpiresIn: localStorage.getItem("expires_in"), - Scope: localStorage.getItem("scope"), - RefreshToken: localStorage.getItem("refresh_token"), - CreatedAt: localStorage.getItem("created_at") - }, - startDate: startDate, - endDate: endDate - }), - }).then(async (res) => { - console.log(`response status code: ${res.status}`); - if (res.status === 200) { - let resJson = await res.json(); - const existingArtists = followedArtists; - const updatedArtists = [...existingArtists, ...resJson].filter( - (value, index, self) => self.findIndex(otherItem => otherItem.id === value.id) === index - ); - setFollowedArtists(updatedArtists); - } - return; - }).catch((err) => { - console.log("Some error occured"); - console.log(err); - }); - } - }; - - // Display spotify token - return ( - - - - {disableButton ? (
- ) : ( - )} - -
- ); -} - -export default YourFavoriteSpotifyArtists; \ No newline at end of file