aboutsummaryrefslogtreecommitdiff
path: root/src/site/store
diff options
context:
space:
mode:
authorZephyrrus <[email protected]>2020-07-03 00:35:09 +0300
committerZephyrrus <[email protected]>2020-07-03 00:35:09 +0300
commit7581d13d1cdbd190009dea11549669cfa5cc00ad (patch)
tree9459ed3b7824a230e27cb84f001716bae38e50e5 /src/site/store
parentfeat: refactor preview to support random fragment extraction (diff)
downloadhost.fuwn.me-7581d13d1cdbd190009dea11549669cfa5cc00ad.tar.xz
host.fuwn.me-7581d13d1cdbd190009dea11549669cfa5cc00ad.zip
feat: separate album view into multiple components and use vuex
Diffstat (limited to 'src/site/store')
-rw-r--r--src/site/store/albums.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/site/store/albums.js b/src/site/store/albums.js
new file mode 100644
index 0000000..a33181c
--- /dev/null
+++ b/src/site/store/albums.js
@@ -0,0 +1,56 @@
+/* eslint-disable no-shadow */
+export const state = () => ({
+ list: [],
+ isListLoading: false,
+ albumDetails: {},
+ expandedAlbums: []
+});
+
+export const getters = {
+ isExpanded: state => id => state.expandedAlbums.indexOf(id) > -1,
+ getDetails: state => id => state.albumDetails[id] || {}
+};
+
+export const actions = {
+ async fetch({ commit, dispatch }) {
+ try {
+ commit('albumsRequest');
+ const response = await this.$axios.$get(`albums/mini`);
+
+ commit('setAlbums', response.albums);
+ } 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`);
+
+ commit('setDetails', {
+ id: albumId,
+ details: {
+ links: response.links
+ }
+ });
+ }
+};
+
+export const mutations = {
+ albumsRequest(state) {
+ state.isLoading = true;
+ },
+ setAlbums(state, albums) {
+ state.list = albums;
+ state.isLoading = false;
+ },
+ setDetails(state, { id, details }) {
+ state.albumDetails[id] = details;
+ },
+ toggleExpandedState(state, id) {
+ const foundIndex = state.expandedAlbums.indexOf(id);
+ if (foundIndex > -1) {
+ state.expandedAlbums.splice(foundIndex, 1);
+ } else {
+ state.expandedAlbums.push(id);
+ }
+ }
+};