diff options
| author | Zephyrrus <[email protected]> | 2020-07-03 00:35:09 +0300 |
|---|---|---|
| committer | Zephyrrus <[email protected]> | 2020-07-03 00:35:09 +0300 |
| commit | 7581d13d1cdbd190009dea11549669cfa5cc00ad (patch) | |
| tree | 9459ed3b7824a230e27cb84f001716bae38e50e5 /src/site/store | |
| parent | feat: refactor preview to support random fragment extraction (diff) | |
| download | host.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.js | 56 |
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); + } + } +}; |