mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Update:Remove playlist if all items are removed
This commit is contained in:
parent
c957e9483e
commit
531f947754
@ -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
|
||||
})
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user