From 9ffde04d3e3e4a40ab36a314167f760b6e6de80d Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Tue, 21 May 2024 08:30:43 +0800 Subject: [PATCH 1/2] * Do not auto set a quick bookmark target --- src/renderer/store/modules/playlists.js | 39 ------------------------- 1 file changed, 39 deletions(-) diff --git a/src/renderer/store/modules/playlists.js b/src/renderer/store/modules/playlists.js index 22df83be63659..b51dc10c1a0d7 100644 --- a/src/renderer/store/modules/playlists.js +++ b/src/renderer/store/modules/playlists.js @@ -13,26 +13,6 @@ function generateRandomUniqueId() { return crypto.randomUUID ? crypto.randomUUID() : `id-${Date.now()}-${Math.floor(Math.random() * 10000)}` } -/* -* Function to find the first playlist with 0 videos, or otherwise the most recently accessed. -* This is a good default quick bookmark target if one needs to be set. -*/ -function findEmptyOrLatestPlayedPlaylist(playlists) { - const emptyPlaylist = playlists.find((playlist) => playlist.videos.length === 0) - if (emptyPlaylist) return emptyPlaylist - - let max = -1 - let maxIndex = 0 - for (let i = 0; i < playlists.length; i++) { - if (playlists[i].lastPlayedAt != null && playlists[i].lastPlayedAt > max) { - maxIndex = i - max = playlists[i].lastPlayedAt - } - } - - return playlists[maxIndex] -} - const state = { // Playlist loading takes time on app load (new windows) // This is necessary to let components to know when to start data loading @@ -109,11 +89,6 @@ const actions = { try { await DBPlaylistHandlers.create([payload]) - const noQuickBookmarkSet = !rootState.settings.quickBookmarkTargetPlaylistId || !state.playlists.some((playlist) => playlist._id === rootState.settings.quickBookmarkTargetPlaylistId) - if (noQuickBookmarkSet) { - dispatch('updateQuickBookmarkTargetPlaylistId', payload._id, { root: true }) - } - commit('addPlaylist', payload) } catch (errMessage) { console.error(errMessage) @@ -123,13 +98,6 @@ const actions = { async addPlaylists({ state, commit, rootState, dispatch }, payload) { try { await DBPlaylistHandlers.create(payload) - - const noQuickBookmarkSet = !rootState.settings.quickBookmarkTargetPlaylistId || !state.playlists.some((playlist) => playlist._id === rootState.settings.quickBookmarkTargetPlaylistId) - if (noQuickBookmarkSet) { - const chosenPlaylist = findEmptyOrLatestPlayedPlaylist(payload) - dispatch('updateQuickBookmarkTargetPlaylistId', chosenPlaylist._id, { root: true }) - } - commit('addPlaylists', payload) } catch (errMessage) { console.error(errMessage) @@ -350,13 +318,6 @@ const actions = { } } - // if no quick bookmark is set, try to find another playlist - const noQuickBookmarkSet = !rootState.settings.quickBookmarkTargetPlaylistId || !payload.some((playlist) => playlist._id === rootState.settings.quickBookmarkTargetPlaylistId) - if (noQuickBookmarkSet && payload.length > 0) { - const chosenPlaylist = findEmptyOrLatestPlayedPlaylist(payload) - dispatch('updateQuickBookmarkTargetPlaylistId', chosenPlaylist._id, { root: true }) - } - commit('setAllPlaylists', payload) } commit('setPlaylistsReady', true) From b82014dd7230cbd2b82422516ae33dadc2e1f344 Mon Sep 17 00:00:00 2001 From: PikachuEXE Date: Tue, 21 May 2024 08:47:49 +0800 Subject: [PATCH 2/2] * Allow unsetting quick bookmark target and prompt to set it later when user attempt to quick bookmark --- .../ft-list-playlist/ft-list-playlist.js | 8 +++---- .../ft-list-playlist/ft-list-playlist.vue | 4 +--- .../components/ft-list-video/ft-list-video.js | 18 ++++++++++++-- .../ft-list-video/ft-list-video.vue | 2 +- .../watch-video-info/watch-video-info.js | 24 ++++++++++++++++--- .../watch-video-info/watch-video-info.vue | 1 - static/locales/en-US.yaml | 1 + 7 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/renderer/components/ft-list-playlist/ft-list-playlist.js b/src/renderer/components/ft-list-playlist/ft-list-playlist.js index b88747cd638c9..1726cd6478fb7 100644 --- a/src/renderer/components/ft-list-playlist/ft-list-playlist.js +++ b/src/renderer/components/ft-list-playlist/ft-list-playlist.js @@ -124,10 +124,6 @@ export default defineComponent({ }) }, - handleQuickBookmarkEnabledDisabledClick: function () { - showToast(this.$t('User Playlists.SinglePlaylistView.Toast["This playlist is already being used for quick bookmark."]')) - }, - parseInvidiousData: function () { this.title = this.data.title if (this.thumbnailCanBeShown) { @@ -194,6 +190,10 @@ export default defineComponent({ showToast(this.$t('User Playlists.SinglePlaylistView.Toast.This playlist is now used for quick bookmark')) } }, + disableQuickBookmark() { + this.updateQuickBookmarkTargetPlaylistId(null) + showToast(this.$t('User Playlists.SinglePlaylistView.Toast.Quick bookmark disabled')) + }, ...mapActions([ 'openInExternalPlayer', diff --git a/src/renderer/components/ft-list-playlist/ft-list-playlist.vue b/src/renderer/components/ft-list-playlist/ft-list-playlist.vue index 0f5bed27762b3..0198d37e34276 100644 --- a/src/renderer/components/ft-list-playlist/ft-list-playlist.vue +++ b/src/renderer/components/ft-list-playlist/ft-list-playlist.vue @@ -74,11 +74,9 @@ diff --git a/src/renderer/components/ft-list-video/ft-list-video.js b/src/renderer/components/ft-list-video/ft-list-video.js index cc91ac027bf55..94a3d60d00426 100644 --- a/src/renderer/components/ft-list-video/ft-list-video.js +++ b/src/renderer/components/ft-list-video/ft-list-video.js @@ -7,6 +7,7 @@ import { formatNumber, getRelativeTimeFromDate, openExternalLink, + openInternalPath, showToast, toDistractionFreeTitle, deepCopy @@ -460,7 +461,7 @@ export default defineComponent({ }) }, quickBookmarkIconText: function () { - if (!this.isQuickBookmarkEnabled) { return false } + if (!this.isQuickBookmarkEnabled) { return this.$t('User Playlists.Add to Playlist') } const translationProperties = { playlistName: this.quickBookmarkPlaylist.playlistName, @@ -766,7 +767,13 @@ export default defineComponent({ toggleQuickBookmarked() { if (!this.isQuickBookmarkEnabled) { - // This should be prevented by UI + showToast( + this.$t('Video["Quick Bookmark Disabled. Click Here To Open User Playlists Page To Enable Quick Bookmark"]'), + 5000, + () => { + this.createNewWindowInUserPlaylistsView() + }, + ) return } @@ -776,6 +783,13 @@ export default defineComponent({ this.addToQuickBookmarkPlaylist() } }, + createNewWindowInUserPlaylistsView: function () { + openInternalPath({ + path: '/userPlaylists', + query: {}, + doCreateNewWindow: true, + }) + }, addToQuickBookmarkPlaylist() { const videoData = { videoId: this.id, diff --git a/src/renderer/components/ft-list-video/ft-list-video.vue b/src/renderer/components/ft-list-video/ft-list-video.vue index 8504b3683d92b..98957568e5e75 100644 --- a/src/renderer/components/ft-list-video/ft-list-video.vue +++ b/src/renderer/components/ft-list-video/ft-list-video.vue @@ -56,7 +56,7 @@ @click="togglePlaylistPrompt" /> { + this.createNewWindowInUserPlaylistsView() + }, + ) return } @@ -361,6 +372,13 @@ export default defineComponent({ this.addToQuickBookmarkPlaylist() } }, + createNewWindowInUserPlaylistsView: function () { + openInternalPath({ + path: '/userPlaylists', + query: {}, + doCreateNewWindow: true, + }) + }, addToQuickBookmarkPlaylist() { const videoData = { videoId: this.id, diff --git a/src/renderer/components/watch-video-info/watch-video-info.vue b/src/renderer/components/watch-video-info/watch-video-info.vue index c49c3a1f65446..84bf274be8386 100644 --- a/src/renderer/components/watch-video-info/watch-video-info.vue +++ b/src/renderer/components/watch-video-info/watch-video-info.vue @@ -88,7 +88,6 @@ @click="togglePlaylistPrompt" />