aboutsummaryrefslogtreecommitdiff
path: root/src/site/store/images.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/site/store/images.js')
-rw-r--r--src/site/store/images.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/site/store/images.js b/src/site/store/images.js
new file mode 100644
index 0000000..e87dac1
--- /dev/null
+++ b/src/site/store/images.js
@@ -0,0 +1,56 @@
+/* eslint-disable no-shadow */
+export const state = () => ({
+ files: [],
+ isLoading: false,
+ pagination: {
+ page: 1,
+ limit: 30,
+ totalFiles: 0
+ }
+});
+
+export const getters = {
+ getTotalFiles: state => state.pagination.totalFiles,
+ getFetchedCount: state => state.files.length,
+ shouldPaginate: ({ pagination }) => pagination.totalFiles > pagination.limit,
+ getLimit: ({ pagination }) => pagination.limit
+};
+
+export const actions = {
+ async fetch({ commit, dispatch, state }, page) {
+ commit('setIsLoading');
+
+ page = page || 1;
+
+ try {
+ const response = await this.$axios.$get(`files`, { params: { limit: state.pagination.limit, page } });
+
+ commit('updateFiles', { files: response.files });
+ commit('updatePaginationMeta', { totalFiles: response.count, page });
+ } catch (e) {
+ dispatch('alert/set', { text: e.message, error: true }, { root: true });
+ }
+ },
+ async fetchById({ commit, dispatch }) {
+ try {
+ const response = await this.$axios.$get('verify');
+ commit('loginSuccess', response);
+ } catch (e) {
+ dispatch('alert/set', { text: e.message, error: true }, { root: true });
+ }
+ }
+};
+
+export const mutations = {
+ setIsLoading(state) {
+ state.isLoading = true;
+ },
+ updateFiles(state, { files }) {
+ state.files = files || [];
+ state.isLoading = false;
+ },
+ updatePaginationMeta(state, { page, totalFiles }) {
+ state.pagination.page = page || 1;
+ state.pagination.totalFiles = totalFiles || 0;
+ }
+};