1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
export const state = () => ({
files: [],
isLoading: false,
pagination: {
page: 1,
limit: 30,
totalFiles: 0,
},
name: null,
downloadEnabled: false,
});
export const getters = {
getTotalFiles: ({ pagination }) => pagination.totalFiles,
getFetchedCount: ({ files }) => files.length,
shouldPaginate: ({ pagination }) => pagination.totalFiles > pagination.limit,
getLimit: ({ pagination }) => pagination.limit,
getName: ({ name }) => name,
};
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('setFilesAndMeta', { ...response, page });
} catch (e) {
dispatch('alert/set', { text: e.message, error: true }, { root: true });
}
},
async fetchByAlbumId({ commit, dispatch, state }, { id, page }) {
commit('setIsLoading');
page = page || 1;
const response = await this.$axios.$get(`album/${id}/full`, {
params: { limit: state.pagination.limit, page },
});
commit('setFilesAndMeta', { ...response, page });
},
};
export const mutations = {
setIsLoading(state) {
state.isLoading = true;
},
setFilesAndMeta(state, {
files, name, page, count,
}) {
state.files = files || [];
state.name = name ?? null;
state.isLoading = false;
state.pagination.page = page || 1;
state.pagination.totalFiles = count || 0;
},
};
|