Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for deleting music from play queue #115

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/web/components/ContextMenus/TrackContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ const TrackContextMenu = () => {
player.addToNextPlay(Number(dataSourceID))
},
},
{
type: 'item',
label: t`context-menu.delete-from-queue`,
onClick: () => {
player.deleteFromPlaylist(Number(dataSourceID))
}
},
{
type: 'divider',
},
Expand Down
1 change: 1 addition & 0 deletions packages/web/i18n/locales/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
"go-to-album": "Go to album",
"go-to-artist": "Go to artist",
"add-to-queue": "Add to Queue",
"delete-from-queue": "Delete from Queue",
"follow": "Follow",
"unfollow": "Unfollow",
"followed": "Followed",
Expand Down
1 change: 1 addition & 0 deletions packages/web/i18n/locales/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
"go-to-album": "查看专辑",
"go-to-artist": "查看艺人",
"add-to-queue": "添加到播放队列",
"delete-from-queue": "从播放队列中删除",
"unfollow": "取消关注",
"follow": "关注",
"followed": "已关注",
Expand Down
22 changes: 22 additions & 0 deletions packages/web/utils/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,28 @@ export class Player {
this.trackList.splice(Number(this._nextTrackIndex), 0, trackID)
}

/**
* deleteFromPlaylist() - function to remove a track from current play queue
*
* @param trackID
*/

deleteFromPlaylist(trackID: number) {
// Check if the song existed in the tracklist
if (!this.trackList.includes(trackID)) {
return
}
// Check whether we are deleting the content that we are playing
if (this.track?.id != undefined && this.track?.id != trackID){
this.trackList = this.trackList.filter(item => item != trackID)
return
}
// If we are deleting current playing. Switch to the next first
this.prevTrack()
this.trackList = this.trackList.filter(item => item != trackID)
this.nextTrack()
}

/**
*
* @param trackID
Expand Down