Skip to content

Commit

Permalink
Merge pull request #115 from EndCredits/feat-delete-from-playlist
Browse files Browse the repository at this point in the history
Add support for deleting music from play queue
  • Loading branch information
Sherlockouo authored Feb 1, 2024
2 parents 35999eb + ee75308 commit ceabf0c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
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

0 comments on commit ceabf0c

Please sign in to comment.