Skip to content

Commit

Permalink
Front: Add button to delete track from queue (#900)
Browse files Browse the repository at this point in the history
* Front: Add 'New' Playlist button to 'Add to playlist' dialog

* Front: Lint

* Front: Add button to delete track from queue
  • Loading branch information
Arthi-chaud authored Feb 11, 2025
1 parent 4d09f9e commit e7d7d20
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 8 deletions.
54 changes: 46 additions & 8 deletions front/src/components/player/controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import ReleaseTrackContextualMenu from "../contextual-menu/release-track-context
import {
CloseIcon,
ContextualMenuIcon,
DeleteIcon,
DragHandleIcon,
ForwardIcon,
FullscreenIcon,
Expand Down Expand Up @@ -244,7 +245,8 @@ const ExpandedPlayerControls = (
parentSongQuery,
props.track?.songId ?? undefined,
);
const { playlist, cursor, reorder, skipTrack } = usePlayerContext();
const { playlist, cursor, reorder, skipTrack, removeTrack } =
usePlayerContext();
const [selectedTab, selectTab] = useState<"player" | "lyrics" | "playlist">(
"player",
);
Expand Down Expand Up @@ -638,13 +640,49 @@ const ExpandedPlayerControls = (
</Box>
}
trailing={
<Typography color="text.disabled">
{formatDuration(
playlistItem
.track
.duration,
)}
</Typography>
<Grid
container
wrap="nowrap"
columnSpacing={
1
}
>
<Grid
item
sx={{
display:
"flex",
alignItems:
"center",
}}
>
<Typography color="text.disabled">
{formatDuration(
playlistItem
.track
.duration,
)}
</Typography>
</Grid>
<Grid
item
>
<IconButton
size={
"small"
}
onClick={() =>
removeTrack(
cursor +
1 +
index,
)
}
>
<DeleteIcon />
</IconButton>
</Grid>
</Grid>
}
onClick={() => {
let toSkip =
Expand Down
10 changes: 10 additions & 0 deletions front/src/contexts/player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type PlayerActions = {
playPreviousTrack: () => void;
reorder: (reordering: Record<"from" | "to", number>) => void;
emptyPlaylist: () => void;
removeTrack: (trackIndex: number) => void;
};

const PlayerContext = createContext<PlayerState & PlayerActions>({
Expand All @@ -60,6 +61,7 @@ const PlayerContext = createContext<PlayerState & PlayerActions>({
playPreviousTrack: () => {},
reorder: () => {},
emptyPlaylist: () => {},
removeTrack: () => {},
});

const PlayerContextProvider = (props: { children: JSX.Element }) => {
Expand Down Expand Up @@ -116,6 +118,14 @@ const PlayerContextProvider = (props: { children: JSX.Element }) => {
};
});
},
removeTrack: (trackIndex) => {
setPlayerState((state) => ({
cursor: state.cursor,
playlist: state.playlist.filter(
(_, i) => i !== trackIndex,
),
}));
},
playPreviousTrack: () => {
setPlayerState((state) => {
let newCursor = state.cursor;
Expand Down

0 comments on commit e7d7d20

Please sign in to comment.