Update:Remove playlist if all items are removed

This commit is contained in:
advplyr 2022-11-27 12:04:49 -06:00
parent c957e9483e
commit 531f947754
2 changed files with 30 additions and 8 deletions

View File

@ -215,13 +215,19 @@ export default {
this.$axios
.$delete(routepath)
.then((updatedPlaylist) => {
console.log(`Item removed from playlist`, updatedPlaylist)
this.$toast.success('Item removed from playlist')
this.processingRemove = false
if (!updatedPlaylist.items.length) {
console.log(`All items removed so playlist was removed`, updatedPlaylist)
this.$toast.success(this.$strings.ToastPlaylistRemoveSuccess)
} else {
console.log(`Item removed from playlist`, updatedPlaylist)
this.$toast.success('Item removed from playlist')
}
})
.catch((error) => {
console.error('Failed to remove item from playlist', error)
this.$toast.error('Failed to remove item from playlist')
})
.finally(() => {
this.processingRemove = false
})
}

View File

@ -100,9 +100,18 @@ class PlaylistController {
playlist.removeItem(itemToRemove.libraryItemId, itemToRemove.episodeId)
const jsonExpanded = playlist.toJSONExpanded(this.db.libraryItems)
await this.db.updateEntity('playlist', playlist)
SocketAuthority.emitter('playlist_updated', jsonExpanded)
res.json(playlist.toJSONExpanded(this.db.libraryItems))
// Playlist is removed when there are no items
if (!playlist.items.length) {
Logger.info(`[PlaylistController] Playlist "${playlist.name}" has no more items - removing it`)
await this.db.removeEntity('playlist', playlist.id)
SocketAuthority.emitter('playlist_removed', jsonExpanded)
} else {
await this.db.updateEntity('playlist', playlist)
SocketAuthority.emitter('playlist_updated', jsonExpanded)
}
res.json(jsonExpanded)
}
// POST: api/playlists/:id/batch/add
@ -152,8 +161,15 @@ class PlaylistController {
const jsonExpanded = playlist.toJSONExpanded(this.db.libraryItems)
if (hasUpdated) {
await this.db.updateEntity('playlist', playlist)
SocketAuthority.emitter('playlist_updated', jsonExpanded)
// Playlist is removed when there are no items
if (!playlist.items.length) {
Logger.info(`[PlaylistController] Playlist "${playlist.name}" has no more items - removing it`)
await this.db.removeEntity('playlist', playlist.id)
SocketAuthority.emitter('playlist_removed', jsonExpanded)
} else {
await this.db.updateEntity('playlist', playlist)
SocketAuthority.emitter('playlist_updated', jsonExpanded)
}
}
res.json(jsonExpanded)
}