Skip to content

Commit

Permalink
! Fix small stuff, errors on app boot
Browse files Browse the repository at this point in the history
  • Loading branch information
PikachuEXE committed May 18, 2023
1 parent 370b9e2 commit c9680c1
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/renderer/store/modules/playlists.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ const actions = {

async grabAllPlaylists({ commit, dispatch, state }) {
try {
const payload = await DBPlaylistHandlers.find()
console.log('grabAllPlaylists >>')
console.log({ payload })
const payload = (await DBPlaylistHandlers.find()).filter((e) => e != null)
if (payload.length === 0) {
dispatch('addPlaylists', state.defaultPlaylists)
} else {
Expand All @@ -93,8 +91,8 @@ const actions = {
})

if (findFavorites.length === 0) {
dispatch('addPlaylist', state.playlists[0])
payload.push(state.playlists[0])
dispatch('addPlaylist', state.defaultPlaylists.find((e) => e._id === 'favorites'))
payload.push(state.defaultPlaylists[0])
} else {
const favoritesPlaylist = findFavorites[0]

Expand All @@ -107,14 +105,14 @@ const actions = {
}

if (findWatchLater.length === 0) {
dispatch('addPlaylist', state.playlists[1])
payload.push(state.playlists[1])
dispatch('addPlaylist', state.defaultPlaylists.find((e) => e._id === 'watchLater'))
payload.push(state.defaultPlaylists[1])
} else {
const watchLaterPlaylist = findFavorites[0]
const watchLaterPlaylist = findWatchLater[0]

if (watchLaterPlaylist._id !== 'favorites') {
if (watchLaterPlaylist._id !== 'watchLater') {
const oldId = watchLaterPlaylist._id
watchLaterPlaylist._id = 'favorites'
watchLaterPlaylist._id = 'watchLater'
dispatch('addPlaylist', watchLaterPlaylist)
dispatch('removePlaylist', oldId)
}
Expand Down Expand Up @@ -231,15 +229,15 @@ const mutations = {
},

removeVideo(state, payload) {
const playlist = state.playlists.findIndex(playlist => playlist._id === payload._id)
if (playlist !== -1) {
state.playlists[playlist].videos = state.playlists[playlist].videos.filter(video => video.videoId !== payload.videoId)
const playlist = state.playlists.find(playlist => playlist._id === payload._id)
if (playlist) {
playlist.videos = playlist.videos.filter(video => video.videoId !== payload.videoId)
}
},

removeVideos(state, payload) {
const playlist = state.playlists.findIndex(playlist => playlist._id === payload.playlistId)
if (playlist !== -1) {
const playlist = state.playlists.find(playlist => playlist._id === payload.playlistId)
if (playlist) {
playlist.videos = playlist.videos.filter(video => payload.videoId.indexOf(video) === -1)
}
},
Expand Down

0 comments on commit c9680c1

Please sign in to comment.