diff options
Diffstat (limited to 'src/site/store')
| -rw-r--r-- | src/site/store/album.js | 0 | ||||
| -rw-r--r-- | src/site/store/albums.js | 75 |
2 files changed, 74 insertions, 1 deletions
diff --git a/src/site/store/album.js b/src/site/store/album.js new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/site/store/album.js diff --git a/src/site/store/albums.js b/src/site/store/albums.js index a33181c..d5d45ce 100644 --- a/src/site/store/albums.js +++ b/src/site/store/albums.js @@ -1,4 +1,6 @@ /* eslint-disable no-shadow */ +import Vue from 'vue'; + export const state = () => ({ list: [], isListLoading: false, @@ -18,10 +20,13 @@ export const actions = { const response = await this.$axios.$get(`albums/mini`); commit('setAlbums', response.albums); + + return response; } catch (e) { dispatch('alert/set', { text: e.message, error: true }, { root: true }); } }, + async fetchDetails({ commit }, albumId) { const response = await this.$axios.$get(`album/${albumId}/links`); @@ -31,6 +36,52 @@ export const actions = { links: response.links } }); + + return response; + }, + + async createAlbum({ commit }, name) { + const response = await this.$axios.$post(`album/new`, { name }); + + commit('addAlbum', response.data); + + return response; + }, + + async deleteAlbum({ commit }, albumId) { + const response = await this.$axios.$delete(`album/${albumId}`); + + commit('removeAlbum', albumId); + + return response; + }, + + async createLink({ commit }, albumId) { + const response = await this.$axios.$post(`album/link/new`, { albumId }); + + commit('addAlbumLink', { albumId, data: response.data }); + + return response; + }, + + async updateLinkOptions({ commit }, { albumId, linkOpts }) { + const response = await this.$axios.$post(`album/link/edit`, { + identifier: linkOpts.identifier, + enableDownload: linkOpts.enableDownload, + enabled: linkOpts.enabled + }); + + commit('updateAlbumLinkOpts', { albumId, linkOpts: response.data }); + + return response; + }, + + async deleteLink({ commit }, { albumId, identifier }) { + const response = await this.$axios.$delete(`album/link/delete/${identifier}`); + + commit('removeAlbumLink', { albumId, identifier }); + + return response; } }; @@ -42,8 +93,30 @@ export const mutations = { state.list = albums; state.isLoading = false; }, + addAlbum(state, album) { + state.list.unshift(album); + }, + removeAlbum(state, albumId) { + // state.list = state.list.filter(({ id }) => id !== albumId); + const foundIndex = state.list.findIndex(({ id }) => id === albumId); + state.list.splice(foundIndex, 1); + }, setDetails(state, { id, details }) { - state.albumDetails[id] = details; + Vue.set(state.albumDetails, id, details); + }, + addAlbumLink(state, { albumId, data }) { + state.albumDetails[albumId].links.push(data); + }, + updateAlbumLinkOpts(state, { albumId, linkOpts }) { + const foundIndex = state.albumDetails[albumId].links.findIndex( + ({ identifier }) => identifier === linkOpts.identifier + ); + const link = state.albumDetails[albumId].links[foundIndex]; + state.albumDetails[albumId].links[foundIndex] = { ...link, ...linkOpts }; + }, + removeAlbumLink(state, { albumId, identifier }) { + const foundIndex = state.albumDetails[albumId].links.findIndex(({ identifier: id }) => id === identifier); + state.albumDetails[albumId].links.splice(foundIndex, 1); }, toggleExpandedState(state, id) { const foundIndex = state.expandedAlbums.indexOf(id); |