Skip to content

Commit

Permalink
lol spinny loading circle
Browse files Browse the repository at this point in the history
  • Loading branch information
sam9116 committed May 25, 2024
1 parent 31dd28e commit 80cb7e6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 33 deletions.
4 changes: 3 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Grid, Box, Button } from "@mui/material";
import YourFavoriteSpotifyArtists from "./YourFavoriteSpotifyArtists.js";
import PickDate from "./PickDate.js";
import ConcertList from "./ConcertList.js";
import AuthorizeSpotify from "./AuthorizeSpotify.js";
import SharePage from "./SharePage.js";
import html2canvas from "html2canvas";
import canvas2image from "@reglendo/canvas2image";
Expand All @@ -18,6 +17,7 @@ function App() {
let cachedStartDate = localStorage.getItem("startDate");
let cachedEndDate = localStorage.getItem("endDate");
const [concerts, setConcerts] = useState([]);
const [isRequestTriggered, setIsRequestTriggered] = useState(false);
//all concerts is used to reoptimize the whole route... based on incoming concert
const [allConcerts, setAllConcerts] = useState([]);
const [userLocation, setUserLocation] = useState(null);
Expand Down Expand Up @@ -106,6 +106,7 @@ function App() {
setFollowedArtists={setFollowedArtists}
startDate={startDate}
endDate={endDate}
setIsRequestTriggered={setIsRequestTriggered}
/>
<Router>
<Routes>
Expand All @@ -126,6 +127,7 @@ function App() {
<YourSpotifyArtistsWithShows
artists={followedArtists}
onChildClick={handleChildClick}
isRequestTriggered={isRequestTriggered}
/>
<ConcertList
setConcerts={setConcerts}
Expand Down
5 changes: 3 additions & 2 deletions src/GetSpotifyPlaylistArtistsWithShows.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { Grid, Stack, TextField, Button } from '@mui/material';

function GetSpotifyPlaylistArtistsWithShows({followedArtists, setFollowedArtists, startDate, endDate}) {
function GetSpotifyPlaylistArtistsWithShows({followedArtists, setFollowedArtists, startDate, endDate, setIsRequestTriggered}) {
const [spotifyPlayList, setSpotifyPlaylist] = useState("");
let handleSubmit = async (e) => {
e.preventDefault();
Expand All @@ -11,7 +11,7 @@ function GetSpotifyPlaylistArtistsWithShows({followedArtists, setFollowedArtists
const endIndex = url.indexOf("?"); // Find the index of the question mark

const extractedPlaylistId = url.substring(startIndex, endIndex);

setIsRequestTriggered(true);
await fetch(`${process.env.REACT_APP_BACKEND}/FindArtistWithShows/GetSpotifyPlaylistArtistsWithShows`, {
method: 'POST',
headers: {
Expand All @@ -37,6 +37,7 @@ function GetSpotifyPlaylistArtistsWithShows({followedArtists, setFollowedArtists
console.log("Some error occured");
console.log(err);
});
setIsRequestTriggered(false);
};

return (<Grid>
Expand Down
67 changes: 37 additions & 30 deletions src/YourSpotifyArtistsWithShows.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
import React, {useState, useEffect} from 'react';
import { Grid } from '@mui/material';
import React, { useState, useEffect } from 'react';
import { Grid, CircularProgress } from '@mui/material';
import SwipeableTextMobileStepper from './ArtistsCarrousel'

function YourSpotifyArtistsWithShows({ artists, onChildClick}) {
const [groupedNames, setGroupedNames] = useState({});
useEffect(() => {
if (!artists) return
artists.sort((a, b) => a.name.localeCompare(b.name));
const grouped = artists.reduce((acc, artist) => {
const artistNameRaw = artist.name.toUpperCase();
const firstLetter = artistNameRaw[0];

acc[firstLetter] = acc[firstLetter] || [];
acc[firstLetter].push(artist);

return acc;
}, {});
console.log(grouped);
setGroupedNames(grouped);
}, [artists]);

const handleClick = (artistName) => {
onChildClick(artistName);
};

return (
<Grid>
<p>Artists from your playlist</p>
{!!artists && <SwipeableTextMobileStepper groupedNames={groupedNames} handleArtistClick={handleClick} />}
</Grid>
);
function YourSpotifyArtistsWithShows({ artists, onChildClick, isRequestTriggered }) {
const [groupedNames, setGroupedNames] = useState({});
const [isLoading, setIsLoading] = useState(false);

useEffect(() => {
if (!artists) return
artists.sort((a, b) => a.name.localeCompare(b.name));
const grouped = artists.reduce((acc, artist) => {
const artistNameRaw = artist.name.toUpperCase();
const firstLetter = artistNameRaw[0];

acc[firstLetter] = acc[firstLetter] || [];
acc[firstLetter].push(artist);

return acc;
}, {});
setGroupedNames(grouped);
}, [artists]);

useEffect(()=>{
setIsLoading(isRequestTriggered);
}, [isRequestTriggered])


const handleClick = (artistName) => {
onChildClick(artistName);
};

return (
<Grid>
<p>Artists from your playlist</p>
{!!artists && <SwipeableTextMobileStepper groupedNames={groupedNames} handleArtistClick={handleClick} />}
{isLoading && <CircularProgress />}
</Grid>
);
}


Expand Down

0 comments on commit 80cb7e6

Please sign in to comment.