aboutsummaryrefslogtreecommitdiff
path: root/src/site/store/albums.js
diff options
context:
space:
mode:
authorZephyrrus <[email protected]>2020-07-04 03:26:35 +0300
committerZephyrrus <[email protected]>2020-07-04 03:26:35 +0300
commit92be4504ccb8f6d918013e5c33870858cd22376a (patch)
treec66a0980f9905118e02626b976f2084f5363cb4d /src/site/store/albums.js
parentchore: add nsfw flag to migration (diff)
downloadhost.fuwn.me-92be4504ccb8f6d918013e5c33870858cd22376a.tar.xz
host.fuwn.me-92be4504ccb8f6d918013e5c33870858cd22376a.zip
feat: refactor most of the album components to use store for presentation and actions
Diffstat (limited to 'src/site/store/albums.js')
-rw-r--r--src/site/store/albums.js75
1 files changed, 74 insertions, 1 deletions
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);