diff --git a/client/components/modals/collections/AddCreateModal.vue b/client/components/modals/collections/AddCreateModal.vue index f21562b6..ceb66032 100644 --- a/client/components/modals/collections/AddCreateModal.vue +++ b/client/components/modals/collections/AddCreateModal.vue @@ -41,7 +41,8 @@ export default { data() { return { newCollectionName: '', - processing: false + processing: false, + collections: [] } }, watch: { @@ -78,9 +79,6 @@ export default { selectedLibraryItemId() { return this.selectedLibraryItem ? this.selectedLibraryItem.id : null }, - collections() { - return this.$store.state.user.collections || [] - }, sortedCollections() { return this.collections .map((c) => { @@ -112,7 +110,19 @@ export default { }, methods: { 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) { if (!this.selectedLibraryItemId && !this.selectedBookIds.length) return diff --git a/client/store/user.js b/client/store/user.js index 852b0abb..d667a3db 100644 --- a/client/store/user.js +++ b/client/store/user.js @@ -10,9 +10,7 @@ export const state = () => ({ collapseBookSeries: false }, settingsListeners: [], - collections: [], - collectionsLoaded: false, - collectionsListeners: [] + collections: [] }) export const getters = { @@ -113,20 +111,6 @@ export const actions = { console.error('Failed to update settings', error) 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) { 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) { var index = state.collections.findIndex(c => c.id === collection.id) if (index >= 0) { @@ -192,18 +171,8 @@ export const mutations = { } else { state.collections.push(collection) } - state.collectionsListeners.forEach((listener) => listener.meth()) }, removeCollection(state, collection) { 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) - }, + } } \ No newline at end of file diff --git a/server/controllers/CollectionController.js b/server/controllers/CollectionController.js index 00a8687c..8508eb73 100644 --- a/server/controllers/CollectionController.js +++ b/server/controllers/CollectionController.js @@ -18,8 +18,7 @@ class CollectionController { } findAll(req, res) { - var collections = this.db.collections.filter(c => c.userId === req.user.id) - var expandedCollections = collections.map(c => c.toJSONExpanded(this.db.libraryItems)) + var expandedCollections = this.db.collections.map(c => c.toJSONExpanded(this.db.libraryItems)) res.json(expandedCollections) }