Fix:Remove collections when removing library

This commit is contained in:
advplyr 2022-11-11 17:44:19 -06:00
parent 6f901defd6
commit 28feed6ea2
6 changed files with 55 additions and 38 deletions

View File

@ -1,7 +1,7 @@
<template>
<modals-modal v-model="show" name="collections" :processing="processing" :width="500" :height="'unset'">
<template #outer>
<div class="absolute top-0 left-0 p-5 w-2/3 overflow-hidden">
<div class="absolute top-0 left-0 p-5 w-2/3 overflow-hidden pointer-events-none">
<p class="font-book text-3xl text-white truncate">{{ title }}</p>
</div>
</template>
@ -41,8 +41,7 @@ export default {
data() {
return {
newCollectionName: '',
processing: false,
collections: []
processing: false
}
},
watch: {
@ -70,6 +69,9 @@ export default {
}
return this.selectedLibraryItem ? this.selectedLibraryItem.media.metadata.title : ''
},
collections() {
return this.$store.state.libraries.collections || []
},
bookCoverAspectRatio() {
return this.$store.getters['libraries/getBookCoverAspectRatio']
},
@ -110,19 +112,23 @@ export default {
},
methods: {
loadCollections() {
this.processing = true
this.$axios
.$get(`/api/libraries/${this.currentLibraryId}/collections`)
.then((data) => {
this.collections = data.results || []
})
.catch((error) => {
console.error('Failed to get collections', error)
this.$toast.error('Failed to load collections')
})
.finally(() => {
this.processing = false
})
if (!this.collections.length) {
this.processing = true
this.$axios
.$get(`/api/libraries/${this.currentLibraryId}/collections`)
.then((data) => {
if (data.results) {
this.$store.commit('libraries/setCollections', data.results || [])
}
})
.catch((error) => {
console.error('Failed to get collections', error)
this.$toast.error('Failed to load collections')
})
.finally(() => {
this.processing = false
})
}
},
removeFromCollection(collection) {
if (!this.selectedLibraryItemId && !this.selectedBookIds.length) return

View File

@ -298,10 +298,10 @@ export default {
this.$store.commit('user/updateMediaProgress', payload)
},
collectionAdded(collection) {
this.$store.commit('user/addUpdateCollection', collection)
this.$store.commit('libraries/addUpdateCollection', collection)
},
collectionUpdated(collection) {
this.$store.commit('user/addUpdateCollection', collection)
this.$store.commit('libraries/addUpdateCollection', collection)
},
collectionRemoved(collection) {
if (this.$route.name.startsWith('collection')) {
@ -309,7 +309,7 @@ export default {
this.$router.replace(`/library/${this.$store.state.libraries.currentLibraryId}/bookshelf/collections`)
}
}
this.$store.commit('user/removeCollection', collection)
this.$store.commit('libraries/removeCollection', collection)
},
rssFeedOpen(data) {
this.$store.commit('feeds/addFeed', data)

View File

@ -52,7 +52,7 @@ export default {
return redirect('/')
}
store.commit('user/addUpdateCollection', collection)
store.commit('libraries/addUpdateCollection', collection)
return {
collectionId: collection.id
}
@ -80,7 +80,7 @@ export default {
return this.collection.description || ''
},
collection() {
return this.$store.getters['user/getCollection'](this.collectionId)
return this.$store.getters['libraries/getCollection'](this.collectionId) || {}
},
playableBooks() {
return this.bookItems.filter((book) => {

View File

@ -11,7 +11,8 @@ export const state = () => ({
filterData: null,
seriesSortBy: 'name',
seriesSortDesc: false,
seriesFilterBy: 'all'
seriesFilterBy: 'all',
collections: []
})
export const getters = {
@ -55,6 +56,9 @@ export const getters = {
getBookCoverAspectRatio: (state, getters) => {
if (!getters.getCurrentLibrarySettings || isNaN(getters.getCurrentLibrarySettings.coverAspectRatio)) return 1
return getters.getCurrentLibrarySettings.coverAspectRatio === Constants.BookCoverAspectRatio.STANDARD ? 1.6 : 1
},
getCollection: state => id => {
return state.collections.find(c => c.id === id)
}
}
@ -111,6 +115,7 @@ export const actions = {
commit('setLibraryIssues', issues)
commit('setLibraryFilterData', filterData)
commit('setCurrentLibrary', libraryId)
commit('setCollections', [])
return data
})
.catch((error) => {
@ -301,5 +306,19 @@ export const mutations = {
},
setSeriesFilterBy(state, filterBy) {
state.seriesFilterBy = filterBy
},
setCollections(state, collections) {
state.collections = collections
},
addUpdateCollection(state, collection) {
var index = state.collections.findIndex(c => c.id === collection.id)
if (index >= 0) {
state.collections.splice(index, 1, collection)
} else {
state.collections.push(collection)
}
},
removeCollection(state, collection) {
state.collections = state.collections.filter(c => c.id !== collection.id)
}
}

View File

@ -9,8 +9,7 @@ export const state = () => ({
collapseSeries: false,
collapseBookSeries: false
},
settingsListeners: [],
collections: []
settingsListeners: []
})
export const getters = {
@ -57,9 +56,6 @@ export const getters = {
if (!state.user) return false
if (getters.getUserCanAccessAllLibraries) return true
return getters.getLibrariesAccessible.includes(libraryId)
},
getCollection: state => id => {
return state.collections.find(c => c.id === id)
}
}
@ -163,16 +159,5 @@ export const mutations = {
},
removeSettingsListener(state, listenerId) {
state.settingsListeners = state.settingsListeners.filter(l => l.id !== listenerId)
},
addUpdateCollection(state, collection) {
var index = state.collections.findIndex(c => c.id === collection.id)
if (index >= 0) {
state.collections.splice(index, 1, collection)
} else {
state.collections.push(collection)
}
},
removeCollection(state, collection) {
state.collections = state.collections.filter(c => c.id !== collection.id)
}
}

View File

@ -131,6 +131,13 @@ class LibraryController {
// Remove library watcher
this.watcher.removeLibrary(library)
// Remove collections for library
var collections = this.db.collections.filter(c => c.libraryId === library.id)
for (const collection of collections) {
Logger.info(`[Server] deleting collection "${collection.name}" for library "${library.name}"`)
await this.db.removeEntity('collection', collection.id)
}
// Remove items in this library
var libraryItems = this.db.libraryItems.filter(li => li.libraryId === library.id)
Logger.info(`[Server] deleting library "${library.name}" with ${libraryItems.length} items"`)