diff --git a/client/components/tables/playlist/ItemTableRow.vue b/client/components/tables/playlist/ItemTableRow.vue index a6c0a8e1..7688f6a5 100644 --- a/client/components/tables/playlist/ItemTableRow.vue +++ b/client/components/tables/playlist/ItemTableRow.vue @@ -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 }) } diff --git a/server/controllers/PlaylistController.js b/server/controllers/PlaylistController.js index bbed89fd..df9afa00 100644 --- a/server/controllers/PlaylistController.js +++ b/server/controllers/PlaylistController.js @@ -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) }