Liked Songs - april1703/SpotiReels GitHub Wiki
User's Liked Songs
Overview
The LikedSongs.js page displays all of a user's Spotify Liked Songs in a scrollable grid format. It communicates with the backend using the user's refresh token, allowing them to:
- View their saved tracks
- Play songs sending them to global player
- Unlike (remove) songs directly from the interface
- Load more songs incrementally
Responsibilities
- Fetch and render the user's liked tracks
- "Load more" for large libraries
- Allow users to unlike tracks via backend API
- Handle authentication errors
- User Interface grid layout
Functionality
- When a user goes to the Liked Songs page, the client sends
POST /spotify/likedto server. - This gains the
refreshTokenwhich is exchanged for access. - This then calls the
spotify.getMySavedTracks([ limit, offset ]). - For readability,
flattenSavedTracks(...)is used to make a simplified list.
| State Variable | Description |
|---|---|
| items | Array of liked songs |
| loading | Boolean flag for pagination, prevents duplicates |
| error | Human-readable string of errors for user to debug |
| offset | Numeric cursor for pagination |
| total | Total number of liked tracks |
Like/Unlike Feature
Overview
- A user can like and unlike songs using the
LikeButton.
UI
- Heart shaped button on top right of each card when searching on
Searchpage. - When in unlike state, heart is not filled.
- When in like state, heart is filled.
Functionality
- When the user presses the button, the client sends
POST /spotify/likeorPOST /spotify/unliketo the server. - This exchanges the
refreshTokento get access to callspotify.addToMySavedTracks([trackId])orspotify.removeFromMySavedTracks([trackId])