Skip to content

Commit 2632421

Browse files
committed
Add remove video functionality to user playlists
1 parent f1030e9 commit 2632421

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

src/renderer/components/watch-video-playlist/watch-video-playlist.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineComponent, nextTick } from 'vue'
2-
import { mapMutations } from 'vuex'
2+
import { mapMutations, mapActions } from 'vuex'
33
import FtLoader from '../ft-loader/ft-loader.vue'
44
import FtCard from '../ft-card/ft-card.vue'
55
import FtListVideoNumbered from '../ft-list-video-numbered/ft-list-video-numbered.vue'
@@ -534,8 +534,55 @@ export default defineComponent({
534534
this.$emit('pause-player')
535535
},
536536

537+
handleRemoveFromPlaylist: function (video) {
538+
if (!this.isUserPlaylist) {
539+
return
540+
}
541+
542+
const playlistItems = [].concat(this.playlistItems)
543+
const tempPlaylistItems = [].concat(this.playlistItems)
544+
let isUndoClicked = false
545+
546+
const videoIndex = this.playlistItems.findIndex((item) => {
547+
return item.videoId === video.videoId && item.playlistItemId === video.playlistItemId
548+
})
549+
550+
if (videoIndex !== -1) {
551+
// Store the video that was playing before deletion
552+
if (videoIndex === this.currentVideoIndexZeroBased) {
553+
this.prevVideoBeforeDeletion = this.currentVideo
554+
}
555+
556+
playlistItems.splice(videoIndex, 1)
557+
this.playlistItems = playlistItems
558+
559+
showToast(
560+
this.$t('User Playlists.SinglePlaylistView.Toast["Video has been removed. Click here to undo."]'),
561+
5000,
562+
() => {
563+
this.playlistItems = tempPlaylistItems
564+
isUndoClicked = true
565+
}
566+
)
567+
568+
setTimeout(() => {
569+
if (!isUndoClicked) {
570+
this.removeVideo({
571+
_id: this.playlistId,
572+
videoId: video.videoId,
573+
playlistItemId: video.playlistItemId
574+
})
575+
}
576+
}, 5000)
577+
}
578+
},
579+
537580
...mapMutations([
538581
'setCachedPlaylist'
582+
]),
583+
...mapActions([
584+
'removeVideo',
585+
'updatePlaylist'
539586
])
540587
}
541588
})

src/renderer/components/watch-video-playlist/watch-video-playlist.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,11 @@
126126
:playlist-loop="loopEnabled"
127127
:video-index="index"
128128
:is-current-video="currentVideoIndexZeroBased === index"
129+
:can-remove-from-playlist="isUserPlaylist"
129130
appearance="watchPlaylistItem"
130131
:initial-visible-state="index < (currentVideoIndexZeroBased + 4) && index > (currentVideoIndexZeroBased - 4)"
131132
@pause-player="pausePlayer"
133+
@remove-from-playlist="handleRemoveFromPlaylist(item)"
132134
/>
133135
</div>
134136
</div>

0 commit comments

Comments
 (0)