parent
766e74cc51
commit
15f296a780
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"rules": {
|
||||
"no-shadow": ["error", { "allow": ["state"] }]
|
||||
}
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
/* eslint-disable no-shadow */
|
||||
export const state = () => ({
|
||||
files: [],
|
||||
name: null,
|
||||
|
@ -36,6 +35,10 @@ export const actions = {
|
|||
dispatch('alert/set', { text: e.message, error: true }, { root: true });
|
||||
}
|
||||
},
|
||||
// TODO: Fix duplicate code between this store and files store
|
||||
deleteFile({ commit }, fileId) {
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
export const mutations = {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/* eslint-disable no-shadow */
|
||||
import Vue from 'vue';
|
||||
|
||||
export const state = () => ({
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
/* eslint-disable no-shadow */
|
||||
const getDefaultState = () => ({
|
||||
text: null,
|
||||
error: false
|
||||
error: false,
|
||||
});
|
||||
|
||||
export const state = getDefaultState;
|
||||
|
@ -12,7 +11,7 @@ export const actions = {
|
|||
},
|
||||
clear({ commit }) {
|
||||
commit('clear');
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export const mutations = {
|
||||
|
@ -22,5 +21,5 @@ export const mutations = {
|
|||
},
|
||||
clear(state) {
|
||||
Object.assign(state, getDefaultState());
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
/* eslint-disable no-shadow */
|
||||
// only used so I could keep the convention of naming the first param as "state" in mutations
|
||||
const getDefaultState = () => ({
|
||||
loggedIn: false,
|
||||
isLoading: false,
|
||||
user: null,
|
||||
token: null,
|
||||
});
|
||||
|
@ -23,18 +20,14 @@ export const actions = {
|
|||
dispatch('alert/set', { text: e.message, error: true }, { root: true });
|
||||
}
|
||||
},
|
||||
async login({ commit, dispatch }, { username, password }) {
|
||||
async login({ commit }, { username, password }) {
|
||||
commit('loginRequest');
|
||||
|
||||
try {
|
||||
const data = await this.$axios.$post('auth/login', { username, password });
|
||||
this.$axios.setToken(data.token, 'Bearer');
|
||||
const data = await this.$axios.$post('auth/login', { username, password });
|
||||
this.$axios.setToken(data.token, 'Bearer');
|
||||
|
||||
commit('setToken', data.token);
|
||||
commit('loginSuccess', { token: data.token, user: data.user });
|
||||
} catch (e) {
|
||||
dispatch('alert/set', { text: e.message, error: true }, { root: true });
|
||||
}
|
||||
commit('setToken', data.token);
|
||||
commit('loginSuccess', { token: data.token, user: data.user });
|
||||
},
|
||||
async fetchCurrentUser({ commit, dispatch }) {
|
||||
try {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
/* eslint-disable no-shadow */
|
||||
export const state = () => ({
|
||||
development: true,
|
||||
version: '4.0.0',
|
||||
|
@ -9,11 +8,11 @@ export const state = () => ({
|
|||
chunkSize: 90,
|
||||
maxLinksPerAlbum: 5,
|
||||
publicMode: false,
|
||||
userAccounts: false
|
||||
userAccounts: false,
|
||||
});
|
||||
|
||||
export const mutations = {
|
||||
set(state, config) {
|
||||
Object.assign(state, config);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
/* eslint-disable no-shadow */
|
||||
export const state = () => ({
|
||||
files: [],
|
||||
isLoading: false,
|
||||
pagination: {
|
||||
page: 1,
|
||||
limit: 30,
|
||||
totalFiles: 0
|
||||
}
|
||||
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
|
||||
getLimit: ({ pagination }) => pagination.limit,
|
||||
getName: ({ name }) => name,
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
|
@ -23,34 +25,37 @@ export const actions = {
|
|||
page = page || 1;
|
||||
|
||||
try {
|
||||
const response = await this.$axios.$get(`files`, { params: { limit: state.pagination.limit, page } });
|
||||
const response = await this.$axios.$get('files', { params: { limit: state.pagination.limit, page } });
|
||||
|
||||
commit('setFiles', { files: response.files });
|
||||
commit('updatePaginationMeta', { totalFiles: response.count, page });
|
||||
commit('setFilesAndMeta', { ...response, 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 });
|
||||
}
|
||||
}
|
||||
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;
|
||||
},
|
||||
setFiles(state, { files }) {
|
||||
setFilesAndMeta(state, {
|
||||
files, name, page, count,
|
||||
}) {
|
||||
state.files = files || [];
|
||||
state.name = name ?? null;
|
||||
state.isLoading = false;
|
||||
},
|
||||
updatePaginationMeta(state, { page, totalFiles }) {
|
||||
state.pagination.page = page || 1;
|
||||
state.pagination.totalFiles = totalFiles || 0;
|
||||
}
|
||||
state.pagination.totalFiles = count || 0;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import config from '../../../dist/config.json';
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export const actions = {
|
||||
async nuxtClientInit({ commit, dispatch }) {
|
||||
commit('config/set', config);
|
||||
|
@ -8,8 +9,8 @@ export const actions = {
|
|||
if (!cookies.token) return dispatch('auth/logout');
|
||||
|
||||
commit('auth/setToken', cookies.token);
|
||||
await dispatch('auth/verify');
|
||||
}
|
||||
return dispatch('auth/verify');
|
||||
},
|
||||
/* alert({ commit }, payload) {
|
||||
if (!payload) return commit('alert', null);
|
||||
commit('alert', {
|
||||
|
|
Loading…
Reference in New Issue