From ce8c5af1ceac5a950b62c7181e18c9527535d729 Mon Sep 17 00:00:00 2001 From: Scald <104459145+Arikatsu@users.noreply.github.com> Date: Thu, 24 Nov 2022 10:24:22 +0530 Subject: [PATCH] Let user delete `Tracks` from playlists --- src/backend/playlist.ts | 7 ++++-- src/css/Playlist.scss | 1 + src/ui/components/playlist/PlaylistTrack.tsx | 8 ++++--- src/ui/components/playlist/PlaylistTracks.tsx | 23 +++++++++++++++---- src/ui/pages/PlaylistPage.tsx | 11 ++++++++- 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/backend/playlist.ts b/src/backend/playlist.ts index 3ed4410..b52ca55 100644 --- a/src/backend/playlist.ts +++ b/src/backend/playlist.ts @@ -114,9 +114,12 @@ export async function addTrackToPlaylist(playlistId: string, track: TrackData): * @param playlistId The ID of the playlist. * @param index The index of the track to remove. */ -export async function removeTrackFromPlaylist(playlistId: string, index: string): Promise { +export async function removeTrackFromPlaylist(playlistId: string, index: number): Promise { const response = await fetch(`${targetRoute}/playlist/${playlistId}?type=remove`, { - method: "PATCH", headers: { Authorization: token() }, + method: "PATCH", headers: { + Authorization: token(), + "Content-Type": "application/json" + }, body: JSON.stringify({ index }) }); diff --git a/src/css/Playlist.scss b/src/css/Playlist.scss index 5d99670..1be11b2 100644 --- a/src/css/Playlist.scss +++ b/src/css/Playlist.scss @@ -75,6 +75,7 @@ color: #fff; text-align: center; margin-top: 20px; + margin-bottom: 20px; &:hover { background-color: transparent; diff --git a/src/ui/components/playlist/PlaylistTrack.tsx b/src/ui/components/playlist/PlaylistTrack.tsx index 8132c82..2e7ce51 100644 --- a/src/ui/components/playlist/PlaylistTrack.tsx +++ b/src/ui/components/playlist/PlaylistTrack.tsx @@ -6,13 +6,14 @@ import { player, playFromResult } from "@backend/audio"; import Button from "@components/common/Button"; import { displayModal } from "@components/common/Modal"; -import { faPause, faPlay, faAdd, faShare, faCopy, faDownload } from "@fortawesome/free-solid-svg-icons"; +import { faPause, faPlay, faAdd, faShare, faCopy, faDownload, faDeleteLeft } from "@fortawesome/free-solid-svg-icons"; import "@css/Playlist.scss"; interface IProps { track: TrackData; - onClick: () => void; + setTrack: () => void; + removeTrack: () => void; } interface IState { @@ -64,7 +65,7 @@ class PlaylistTrack extends React.Component { render() { const track = this.props.track; return ( -
+
{this.state.playlist.tracks.length > 0 ? ( - + ) : (

No tracks found.

)}