mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-22 00:07:52 +01:00
Fix:Show only collections for selected library #1130
This commit is contained in:
parent
4cbc8676c6
commit
6f901defd6
@ -41,7 +41,8 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
newCollectionName: '',
|
newCollectionName: '',
|
||||||
processing: false
|
processing: false,
|
||||||
|
collections: []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -78,9 +79,6 @@ export default {
|
|||||||
selectedLibraryItemId() {
|
selectedLibraryItemId() {
|
||||||
return this.selectedLibraryItem ? this.selectedLibraryItem.id : null
|
return this.selectedLibraryItem ? this.selectedLibraryItem.id : null
|
||||||
},
|
},
|
||||||
collections() {
|
|
||||||
return this.$store.state.user.collections || []
|
|
||||||
},
|
|
||||||
sortedCollections() {
|
sortedCollections() {
|
||||||
return this.collections
|
return this.collections
|
||||||
.map((c) => {
|
.map((c) => {
|
||||||
@ -112,7 +110,19 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
loadCollections() {
|
loadCollections() {
|
||||||
this.$store.dispatch('user/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
|
||||||
|
})
|
||||||
},
|
},
|
||||||
removeFromCollection(collection) {
|
removeFromCollection(collection) {
|
||||||
if (!this.selectedLibraryItemId && !this.selectedBookIds.length) return
|
if (!this.selectedLibraryItemId && !this.selectedBookIds.length) return
|
||||||
|
@ -10,9 +10,7 @@ export const state = () => ({
|
|||||||
collapseBookSeries: false
|
collapseBookSeries: false
|
||||||
},
|
},
|
||||||
settingsListeners: [],
|
settingsListeners: [],
|
||||||
collections: [],
|
collections: []
|
||||||
collectionsLoaded: false,
|
|
||||||
collectionsListeners: []
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getters = {
|
export const getters = {
|
||||||
@ -113,20 +111,6 @@ export const actions = {
|
|||||||
console.error('Failed to update settings', error)
|
console.error('Failed to update settings', error)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
},
|
|
||||||
loadCollections({ state, commit }) {
|
|
||||||
if (state.collectionsLoaded) {
|
|
||||||
console.log('Collections already loaded')
|
|
||||||
return state.collections
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.$axios.$get('/api/collections').then((collections) => {
|
|
||||||
commit('setCollections', collections)
|
|
||||||
return collections
|
|
||||||
}).catch((error) => {
|
|
||||||
console.error('Failed to get collections', error)
|
|
||||||
return []
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,11 +164,6 @@ export const mutations = {
|
|||||||
removeSettingsListener(state, listenerId) {
|
removeSettingsListener(state, listenerId) {
|
||||||
state.settingsListeners = state.settingsListeners.filter(l => l.id !== listenerId)
|
state.settingsListeners = state.settingsListeners.filter(l => l.id !== listenerId)
|
||||||
},
|
},
|
||||||
setCollections(state, collections) {
|
|
||||||
state.collectionsLoaded = true
|
|
||||||
state.collections = collections
|
|
||||||
state.collectionsListeners.forEach((listener) => listener.meth())
|
|
||||||
},
|
|
||||||
addUpdateCollection(state, collection) {
|
addUpdateCollection(state, collection) {
|
||||||
var index = state.collections.findIndex(c => c.id === collection.id)
|
var index = state.collections.findIndex(c => c.id === collection.id)
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
@ -192,18 +171,8 @@ export const mutations = {
|
|||||||
} else {
|
} else {
|
||||||
state.collections.push(collection)
|
state.collections.push(collection)
|
||||||
}
|
}
|
||||||
state.collectionsListeners.forEach((listener) => listener.meth())
|
|
||||||
},
|
},
|
||||||
removeCollection(state, collection) {
|
removeCollection(state, collection) {
|
||||||
state.collections = state.collections.filter(c => c.id !== collection.id)
|
state.collections = state.collections.filter(c => c.id !== collection.id)
|
||||||
state.collectionsListeners.forEach((listener) => listener.meth())
|
}
|
||||||
},
|
|
||||||
addCollectionsListener(state, listener) {
|
|
||||||
var index = state.collectionsListeners.findIndex(l => l.id === listener.id)
|
|
||||||
if (index >= 0) state.collectionsListeners.splice(index, 1, listener)
|
|
||||||
else state.collectionsListeners.push(listener)
|
|
||||||
},
|
|
||||||
removeCollectionsListener(state, listenerId) {
|
|
||||||
state.collectionsListeners = state.collectionsListeners.filter(l => l.id !== listenerId)
|
|
||||||
},
|
|
||||||
}
|
}
|
@ -18,8 +18,7 @@ class CollectionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
findAll(req, res) {
|
findAll(req, res) {
|
||||||
var collections = this.db.collections.filter(c => c.userId === req.user.id)
|
var expandedCollections = this.db.collections.map(c => c.toJSONExpanded(this.db.libraryItems))
|
||||||
var expandedCollections = collections.map(c => c.toJSONExpanded(this.db.libraryItems))
|
|
||||||
res.json(expandedCollections)
|
res.json(expandedCollections)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user