Skip to content

Commit

Permalink
* Do not auto set a quick bookmark target
Browse files Browse the repository at this point in the history
  • Loading branch information
PikachuEXE committed Sep 21, 2024
1 parent 9ca2c74 commit 7547b9f
Showing 1 changed file with 0 additions and 39 deletions.
39 changes: 0 additions & 39 deletions src/renderer/store/modules/playlists.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7547b9f

Please sign in to comment.