Skip to content

Commit 7688f81

Browse files
authored
Update playlist page to add remove duplicate videos button for user playlists (#5191)
* $ Remove duplicate line in a method setting a property to the same value * * Update playlist page to add remove duplicate videos button for user playlists * * Make remove watched videos button visible when any video watched * * Use different icon * * Show no. of items to be deleted on prompts
1 parent f7f6143 commit 7688f81

File tree

4 files changed

+106
-4
lines changed

4 files changed

+106
-4
lines changed

src/renderer/components/playlist-info/playlist-info.js

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export default defineComponent({
110110
editMode: false,
111111
showDeletePlaylistPrompt: false,
112112
showRemoveVideosOnWatchPrompt: false,
113+
showRemoveDuplicateVideosPrompt: false,
113114
newTitle: '',
114115
newDescription: '',
115116
deletePlaylistPromptValues: [
@@ -165,6 +166,20 @@ export default defineComponent({
165166
this.$t('Cancel')
166167
]
167168
},
169+
removeVideosOnWatchPromptLabelText() {
170+
return this.$tc(
171+
'User Playlists.Are you sure you want to remove {playlistItemCount} watched videos from this playlist? This cannot be undone',
172+
this.userPlaylistWatchedVideoCount,
173+
{ playlistItemCount: this.userPlaylistWatchedVideoCount },
174+
)
175+
},
176+
removeDuplicateVideosPromptLabelText() {
177+
return this.$tc(
178+
'User Playlists.Are you sure you want to remove {playlistItemCount} duplicate videos from this playlist? This cannot be undone',
179+
this.userPlaylistDuplicateItemCount,
180+
{ playlistItemCount: this.userPlaylistDuplicateItemCount },
181+
)
182+
},
168183

169184
firstVideoIdExists() {
170185
return this.firstVideoId !== ''
@@ -211,6 +226,38 @@ export default defineComponent({
211226
return this.isUserPlaylist ? 'user' : ''
212227
},
213228

229+
userPlaylistAnyVideoWatched() {
230+
if (!this.isUserPlaylist) { return false }
231+
232+
const historyCacheById = this.$store.getters.getHistoryCacheById
233+
return this.selectedUserPlaylist.videos.some((video) => {
234+
return typeof historyCacheById[video.videoId] !== 'undefined'
235+
})
236+
},
237+
// `userPlaylistAnyVideoWatched` is faster than this & this is only needed when prompt shown
238+
userPlaylistWatchedVideoCount() {
239+
if (!this.isUserPlaylist) { return false }
240+
241+
const historyCacheById = this.$store.getters.getHistoryCacheById
242+
return this.selectedUserPlaylist.videos.reduce((count, video) => {
243+
return typeof historyCacheById[video.videoId] !== 'undefined' ? count + 1 : count
244+
}, 0)
245+
},
246+
247+
userPlaylistUniqueVideoIds() {
248+
if (!this.isUserPlaylist) { return new Set() }
249+
250+
return this.selectedUserPlaylist.videos.reduce((set, video) => {
251+
set.add(video.videoId)
252+
return set
253+
}, new Set())
254+
},
255+
userPlaylistDuplicateItemCount() {
256+
if (this.userPlaylistUniqueVideoIds.size === 0) { return 0 }
257+
258+
return this.selectedUserPlaylist.videos.length - this.userPlaylistUniqueVideoIds.size
259+
},
260+
214261
deletePlaylistButtonVisible: function() {
215262
if (!this.isUserPlaylist) { return false }
216263
// Cannot delete during edit
@@ -334,6 +381,43 @@ export default defineComponent({
334381
this.$emit('exit-edit-mode')
335382
},
336383

384+
handleRemoveDuplicateVideosPromptAnswer(option) {
385+
this.showRemoveDuplicateVideosPrompt = false
386+
if (option !== 'delete') { return }
387+
388+
const videoIdsAdded = new Set()
389+
const newVideoItems = this.selectedUserPlaylist.videos.reduce((ary, video) => {
390+
if (videoIdsAdded.has(video.videoId)) { return ary }
391+
392+
ary.push(video)
393+
videoIdsAdded.add(video.videoId)
394+
return ary
395+
}, [])
396+
397+
const removedVideosCount = this.userPlaylistDuplicateItemCount
398+
if (removedVideosCount === 0) {
399+
showToast(this.$t('User Playlists.SinglePlaylistView.Toast["There were no videos to remove."]'))
400+
return
401+
}
402+
403+
const playlist = {
404+
playlistName: this.title,
405+
protected: this.selectedUserPlaylist.protected,
406+
description: this.description,
407+
videos: newVideoItems,
408+
_id: this.id,
409+
}
410+
try {
411+
this.updatePlaylist(playlist)
412+
showToast(this.$tc('User Playlists.SinglePlaylistView.Toast.{videoCount} video(s) have been removed', removedVideosCount, {
413+
videoCount: removedVideosCount,
414+
}))
415+
} catch (e) {
416+
showToast(this.$t('User Playlists.SinglePlaylistView.Toast["There was an issue with updating this playlist."]'))
417+
console.error(e)
418+
}
419+
},
420+
337421
handleRemoveVideosOnWatchPromptAnswer: function (option) {
338422
this.showRemoveVideosOnWatchPrompt = false
339423
if (option !== 'delete') { return }
@@ -346,7 +430,6 @@ export default defineComponent({
346430

347431
if (removedVideosCount === 0) {
348432
showToast(this.$t('User Playlists.SinglePlaylistView.Toast["There were no videos to remove."]'))
349-
this.showRemoveVideosOnWatchPrompt = false
350433
return
351434
}
352435

src/renderer/components/playlist-info/playlist-info.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,14 @@
153153
@click="toggleCopyVideosPrompt"
154154
/>
155155
<ft-icon-button
156-
v-if="!editMode && isUserPlaylist && videoCount > 0"
156+
v-if="!editMode && userPlaylistDuplicateItemCount > 0"
157+
:title="$t('User Playlists.Remove Duplicate Videos')"
158+
:icon="['fas', 'users-slash']"
159+
theme="destructive"
160+
@click="showRemoveDuplicateVideosPrompt = true"
161+
/>
162+
<ft-icon-button
163+
v-if="!editMode && userPlaylistAnyVideoWatched"
157164
:title="$t('User Playlists.Remove Watched Videos')"
158165
:icon="['fas', 'eye-slash']"
159166
theme="destructive"
@@ -203,12 +210,20 @@
203210
/>
204211
<ft-prompt
205212
v-if="showRemoveVideosOnWatchPrompt"
206-
:label="$t('User Playlists.Are you sure you want to remove all watched videos from this playlist? This cannot be undone')"
213+
:label="removeVideosOnWatchPromptLabelText"
207214
:option-names="deletePlaylistPromptNames"
208215
:option-values="deletePlaylistPromptValues"
209216
:is-first-option-destructive="true"
210217
@click="handleRemoveVideosOnWatchPromptAnswer"
211218
/>
219+
<ft-prompt
220+
v-if="showRemoveDuplicateVideosPrompt"
221+
:label="removeDuplicateVideosPromptLabelText"
222+
:option-names="deletePlaylistPromptNames"
223+
:option-values="deletePlaylistPromptValues"
224+
:is-first-option-destructive="true"
225+
@click="handleRemoveDuplicateVideosPromptAnswer"
226+
/>
212227
</div>
213228
</div>
214229
</template>

src/renderer/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ import {
9090
faTimesCircle,
9191
faTrash,
9292
faUsers,
93+
faUsersSlash,
9394
} from '@fortawesome/free-solid-svg-icons'
9495
import {
9596
faBookmark as farBookmark
@@ -188,6 +189,7 @@ library.add(
188189
faTimesCircle,
189190
faTrash,
190191
faUsers,
192+
faUsersSlash,
191193

192194
// solid icons
193195
farBookmark,

static/locales/en-US.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,12 @@ User Playlists:
185185
Cancel: Cancel
186186
Edit Playlist Info: Edit Playlist Info
187187
Copy Playlist: Copy Playlist
188+
Remove Duplicate Videos: Remove Duplicate Videos
188189
Remove Watched Videos: Remove Watched Videos
189190
Enable Quick Bookmark With This Playlist: Enable Quick Bookmark With This Playlist
190191
Quick Bookmark Enabled: Quick Bookmark Enabled
191-
Are you sure you want to remove all watched videos from this playlist? This cannot be undone: Are you sure you want to remove all watched videos from this playlist? This cannot be undone.
192+
Are you sure you want to remove {playlistItemCount} duplicate videos from this playlist? This cannot be undone: Are you sure you want to remove 1 duplicate video from this playlist? This cannot be undone. | Are you sure you want to remove {playlistItemCount} duplicate videos from this playlist? This cannot be undone.
193+
Are you sure you want to remove {playlistItemCount} watched videos from this playlist? This cannot be undone: Are you sure you want to remove 1 watched video from this playlist? This cannot be undone. | Are you sure you want to remove {playlistItemCount} watched videos from this playlist? This cannot be undone.
192194
Delete Playlist: Delete Playlist
193195
Cannot delete the quick bookmark target playlist.: Cannot delete the quick bookmark target playlist.
194196
Are you sure you want to delete this playlist? This cannot be undone: Are you sure you want to delete this playlist? This cannot be undone.

0 commit comments

Comments
 (0)