aboutsummaryrefslogtreecommitdiff
path: root/src/site/store/albums.js
diff options
context:
space:
mode:
authorKana <[email protected]>2020-12-24 21:41:24 +0900
committerGitHub <[email protected]>2020-12-24 21:41:24 +0900
commit2412a60bd4cb2364a477a3af79a8c6dcb6b0ddab (patch)
treedbf2b2cad342f31849a62089dedd40165758af86 /src/site/store/albums.js
parentEnable deleting files with the API key (diff)
parentbug: fix showlist resetting itself every time the page is changed (diff)
downloadhost.fuwn.me-2412a60bd4cb2364a477a3af79a8c6dcb6b0ddab.tar.xz
host.fuwn.me-2412a60bd4cb2364a477a3af79a8c6dcb6b0ddab.zip
Merge pull request #228 from Zephyrrus/begone_trailing_commas
Merge own dev branch into main dev branch
Diffstat (limited to 'src/site/store/albums.js')
-rw-r--r--src/site/store/albums.js136
1 files changed, 136 insertions, 0 deletions
diff --git a/src/site/store/albums.js b/src/site/store/albums.js
new file mode 100644
index 0000000..4f796a1
--- /dev/null
+++ b/src/site/store/albums.js
@@ -0,0 +1,136 @@
+import Vue from 'vue';
+
+export const state = () => ({
+ list: [],
+ isListLoading: false,
+ albumDetails: {},
+ expandedAlbums: [],
+ tinyDetails: []
+});
+
+export const getters = {
+ isExpanded: (state) => (id) => state.expandedAlbums.indexOf(id) > -1,
+ getDetails: (state) => (id) => state.albumDetails[id] || {}
+};
+
+export const actions = {
+ async fetch({ commit }) {
+ commit('albumsRequest');
+ const response = await this.$axios.$get('albums/mini');
+
+ commit('setAlbums', response.albums);
+
+ return response;
+ },
+ async fetchDetails({ commit }, albumId) {
+ const response = await this.$axios.$get(`album/${albumId}/links`);
+
+ commit('setDetails', {
+ id: albumId,
+ details: {
+ 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 createCustomLink({ commit }, { albumId, value }) {
+ const response = await this.$axios.$post('album/link/new', { albumId, identifier: value });
+
+ 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;
+ },
+ async getTinyDetails({ commit }) {
+ const response = await this.$axios.$get('albums/dropdown');
+
+ commit('setTinyDetails', response);
+
+ return response;
+ }
+};
+
+export const mutations = {
+ albumsRequest(state) {
+ state.isLoading = true;
+ },
+ setAlbums(state, albums) {
+ 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 }) {
+ 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);
+ if (foundIndex > -1) state.albumDetails[albumId].links.splice(foundIndex, 1);
+ },
+ toggleExpandedState(state, id) {
+ const foundIndex = state.expandedAlbums.indexOf(id);
+ if (foundIndex > -1) {
+ state.expandedAlbums.splice(foundIndex, 1);
+ } else {
+ state.expandedAlbums.push(id);
+ }
+ },
+ setTinyDetails(state, { albums }) {
+ state.tinyDetails = albums;
+ }
+};