Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 7 additions & 2 deletions src/renderer/components/FtToast/FtToast.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ let idCounter = 0
const toasts = shallowReactive([])

/**
* @param {CustomEvent<{ message: string, time: number | null, action: Function | null }>} event
* @param {CustomEvent<{ message: string, time: number | null, action: Function | null, abortSignal: AbortSignal | null }>} event
*/
function open({ detail: { message, time, action } }) {
function open({ detail: { message, time, action, abortSignal } }) {
/** @type {Toast} */
const toast = {
message,
Expand All @@ -50,6 +50,11 @@ function open({ detail: { message, time, action } }) {
}

toast.timeout = setTimeout(close, time || 3000, toast)
if (abortSignal != null) {
abortSignal.addEventListener('abort', () => {
close(toast)
})
}

nextTick(() => {
toast.isOpen = true
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,15 @@ export const ToastEventBus = new EventTarget()
* @param {string} message
* @param {number} time
* @param {Function} action
* @param {AbortSignal} abortSignal
*/
export function showToast(message, time = null, action = null) {
export function showToast(message, time = null, action = null, abortSignal = null) {
ToastEventBus.dispatchEvent(new CustomEvent('toast-open', {
detail: {
message,
time,
action
action,
abortSignal,
}
}))
}
Expand Down
48 changes: 26 additions & 22 deletions src/renderer/views/Playlist/Playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default defineComponent({
continuationData: this.continuationData,
})
}
this.removeToBeDeletedVideosSometimes()
next()
},
data: function () {
Expand Down Expand Up @@ -80,9 +81,9 @@ export default defineComponent({
videoSearchQuery: '',

promptOpen: false,
deletedVideoIds: [],
deletedPlaylistItemIds: [],
isUndoToast: false
// Present = shown
undoToastAbortController: null,
}
},
computed: {
Expand Down Expand Up @@ -600,44 +601,33 @@ export default defineComponent({
try {
const playlistItems = [].concat(this.playlistItems)
const tempPlaylistItems = [].concat(this.playlistItems)
let isUndoClicked = false

const videoIndex = this.playlistItems.findIndex((video) => {
return video.videoId === videoId && video.playlistItemId === playlistItemId
})

if (videoIndex !== -1) {
this.deletedVideoIds.push(this.playlistItems[videoIndex].videoId)
this.deletedPlaylistItemIds.push(this.playlistItems[videoIndex].playlistItemId)
playlistItems.splice(videoIndex, 1)
this.playlistItems = playlistItems

// Only show toast when no existing toast shown
if (!this.isUndoToast) {
this.isUndoToast = true
if (this.undoToastAbortController == null) {
this.undoToastAbortController = new AbortController()
const actualRemoveVideosTimeout = setTimeout(() => {
this.removeToBeDeletedVideosSometimes()
}, 5000)
showToast(
this.$t('User Playlists.SinglePlaylistView.Toast["Video has been removed. Click here to undo."]'),
5000,
() => {
this.playlistItems = tempPlaylistItems
isUndoClicked = true
this.isUndoToast = false
this.deletedVideoIds = []
clearTimeout(actualRemoveVideosTimeout)
this.deletedPlaylistItemIds = []
}
this.undoToastAbortController = null
},
this.undoToastAbortController.signal,
)
setTimeout(() => {
if (!isUndoClicked) {
this.removeVideos({
_id: this.playlistId,
videoIds: this.deletedVideoIds,
playlistItemIds: this.deletedPlaylistItemIds,
})
this.deletedVideoIds = []
this.deletedPlaylistItemIds = []
this.isUndoToast = false
}
}, 5000)
}
}
} catch (e) {
Expand All @@ -646,6 +636,20 @@ export default defineComponent({
}
},

removeToBeDeletedVideosSometimes() {
if (this.isLoading) { return }

if (this.deletedPlaylistItemIds.length > 0) {
this.removeVideos({
_id: this.playlistId,
playlistItemIds: this.deletedPlaylistItemIds,
})
this.deletedPlaylistItemIds = []
this.undoToastAbortController?.abort()
this.undoToastAbortController = null
}
},

updatePageTitle() {
const playlistTitle = this.playlistTitle
const channelName = this.channelName
Expand Down
2 changes: 1 addition & 1 deletion static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ User Playlists:
This video cannot be moved up.: This video cannot be moved up.
This video cannot be moved down.: This video cannot be moved down.
Video has been removed: Video has been removed
Video has been removed. Click here to undo.: Video has been removed. Click here to undo.
Video has been removed. Click here to undo.: Video has been removed. Click here to undo. Exiting this view will remove them immediately (cannot undo).
There was a problem with removing this video: There was a problem with removing this video

This playlist is already being used for quick bookmark.: This playlist is already being used for quick bookmark.
Expand Down