-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from ECE651-ReWrapped/persist-user-email
Create and view collaborative playlists with users
- Loading branch information
Showing
12 changed files
with
283 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { useParams } from 'react-router-dom'; | ||
import React from 'react'; | ||
import { useEffect, useState } from 'react'; | ||
import { List, ListItem, Divider, ListItemText, ListItemAvatar, Avatar, Box, Typography } from '@mui/material'; | ||
import axios from 'axios'; | ||
|
||
const SelectedPlaylist = () => { | ||
const { playlist_name } = useParams(); | ||
const [tracks, setTracks] = useState([]); | ||
|
||
useEffect(() => { | ||
const fetchApiData = async () => { | ||
try { | ||
const res = await axios.get(`${process.env.REACT_APP_API_LOCAL}/getAllTracksFromPlaylist`, { | ||
params: { | ||
playlist_name: playlist_name | ||
}, | ||
withCredentials: true, | ||
}); | ||
|
||
if (res.status === 200) { | ||
if (res.data.tracks.length === 0) { | ||
setTracks([]); | ||
} else { | ||
const formattedTracks = res.data.tracks.map((item) => ({ | ||
track: item.track_name, | ||
artist: item.artist_name | ||
})); | ||
setTracks(formattedTracks); | ||
} | ||
} else { | ||
console.log("Failed to get tracks from playlist."); | ||
} | ||
} catch (err) { | ||
console.error("Failed to get tracks from playlist: ", err); | ||
} | ||
}; | ||
|
||
fetchApiData(); | ||
}, [playlist_name]); | ||
|
||
return ( | ||
<> | ||
<Typography | ||
padding="5px" | ||
style={{ fontFamily: "sans-serif", fontWeight: 'bold', textAlign: 'center' }} | ||
variant="h4" | ||
marginTop="30px" | ||
gutterBottom | ||
> | ||
Songs in this playlist | ||
</Typography> | ||
{tracks.length > 0 ? ( | ||
<Box sx={{ display: "flex", flexDirection: "column", justifyContent: "center", alignItems: "center", marginTop: '30px' }}> | ||
<List sx={{ width: '100%', maxWidth: 500, bgcolor: '#F0F2F5' }}> | ||
{tracks.map((item, index) => ( | ||
<React.Fragment key={index}> | ||
<ListItem alignItems="flex-start"> | ||
<ListItemAvatar sx={{ padding: '10px' }}> | ||
<Avatar alt={item.artist} src="/static/images/avatar/1.jpg" /> | ||
</ListItemAvatar> | ||
<ListItemText | ||
primary={item.track} | ||
secondary={item.artist} | ||
sx={{ padding: '10px' }} | ||
/> | ||
</ListItem> | ||
<Divider variant="inset" component="li" /> | ||
</React.Fragment> | ||
))} | ||
</List> | ||
</Box> | ||
) : ( | ||
<p>This playlist has no tracks!</p> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default SelectedPlaylist; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React from 'react'; | ||
import { Button, Dialog, DialogTitle, List, ListItemButton, ListItemText, DialogContent } from '@mui/material'; | ||
import { useEffect, useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import axios from 'axios'; | ||
|
||
let playlists = []; | ||
|
||
const SongToPlaylistDialog = ({ songName, songArtist, handleCloseDialog }) => { | ||
const currUserEmail = useSelector(state => state.currentUserDetails.userEmail); | ||
const [hasPlaylists, setHasPlaylists] = useState(false); | ||
|
||
useEffect(() => { | ||
// get all of my playlists only, shared or unshared | ||
const getMyPlaylists = async () => { | ||
playlists = []; | ||
try { | ||
const response = await axios.get(`${process.env.REACT_APP_API_LOCAL}/getSharedPlaylists`, { | ||
params: { | ||
createdByUserEmail: currUserEmail, | ||
sharedWithUsername: undefined // don't set to get all of only my playlists | ||
}, | ||
withCredentials: true, | ||
}); | ||
|
||
if (response.status === 200) { | ||
// there are playlists to my name | ||
response.data.playlists.map((item) => { | ||
playlists.push(item.playlist_name); | ||
}); | ||
setHasPlaylists(true); | ||
} else { | ||
// I dont have any shared playlists | ||
} | ||
|
||
} catch (err) { | ||
console.error("Failed to get user's playlists: ", err); | ||
} | ||
}; | ||
getMyPlaylists(); | ||
}, []); | ||
|
||
const handleAddToChosenPlaylist = (selPlaylist) => { | ||
handleCloseDialog(false); | ||
setHasPlaylists(false); | ||
// store this song to the selected playlist in db | ||
try { | ||
const res = axios.post(`${process.env.REACT_APP_API_LOCAL}/addTrackToPlaylist`, { | ||
playlist_name: selPlaylist, | ||
track_name: songName, | ||
artist_name: songArtist | ||
}); | ||
} catch (err) { | ||
console.error("Failed to add track to the playlist: ", err); | ||
} | ||
}; | ||
|
||
return ( | ||
<Dialog open={true} onClose={() => handleCloseDialog(false)}> | ||
<DialogTitle>Choose a playlist to add this song to</DialogTitle> | ||
<DialogContent> | ||
<List> | ||
{playlists.map((playlist, index) => ( | ||
<ListItemButton key={index} onClick={ () => handleAddToChosenPlaylist(playlist) }> | ||
<ListItemText primary={playlist} /> | ||
</ListItemButton> | ||
))} | ||
</List> | ||
<Button onClick={() => handleCloseDialog(false)}>Done</Button> | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
}; | ||
|
||
export default SongToPlaylistDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.