From 720ffaf0083564c85a07d66a6d303f34706add41 Mon Sep 17 00:00:00 2001 From: Zephyrrus Date: Thu, 2 Jul 2020 02:50:55 +0300 Subject: feat: start refactoring the code to actually use vuex This includes creating multiple stores as needed for components and removing all complex states from components (since all those states should be stored in vuex) --- src/site/store/index.js | 62 +++++++------------------------------------------ 1 file changed, 8 insertions(+), 54 deletions(-) (limited to 'src/site/store/index.js') diff --git a/src/site/store/index.js b/src/site/store/index.js index 1fc2272..8f910ae 100644 --- a/src/site/store/index.js +++ b/src/site/store/index.js @@ -1,66 +1,20 @@ import config from '../../../dist/config.json'; -export const state = () => ({ - loggedIn: false, - user: null, - token: null, - config: null, - alert: null -}); - -/* eslint-disable no-shadow */ -export const mutations = { - loggedIn(state, payload) { - state.loggedIn = payload; - }, - user(state, payload) { - state.user = payload; - }, - token(state, payload) { - state.token = payload; - }, - config(state, payload) { - state.config = payload; - }, - alert(state, payload) { - state.alert = payload; - } -}; export const actions = { - async nuxtClientInit({ commit, dispatch }, { app, req }) { - commit('config', config); + async nuxtClientInit({ commit, dispatch }) { + commit('config/set', config); const cookies = this.$cookies.getAll(); - if (!cookies.token) return dispatch('logout'); + if (!cookies.token) return dispatch('auth/logout'); - commit('token', cookies.token); - try { - const response = await this.$axios.$get('verify'); - dispatch('login', { - token: cookies.token, - user: response.user - }); - } catch (error) { - // dispatch('logout'); - } - }, - login({ commit }, { token, user }) { - this.$cookies.set('token', token); - commit('token', token); - commit('user', user); - commit('loggedIn', true); - }, - logout({ commit }) { - this.$cookies.remove('token'); - commit('token', null); - commit('user', null); - commit('loggedIn', false); - }, - alert({ commit }, payload) { + commit('auth/setToken', cookies.token); + await dispatch('auth/verify'); + } + /* alert({ commit }, payload) { if (!payload) return commit('alert', null); commit('alert', { text: payload.text, error: payload.error }); - } + } */ }; -- cgit v1.2.3 From 15f296a7805b7623f56eab67b74ab0bf93a038e1 Mon Sep 17 00:00:00 2001 From: Zephyrrus Date: Tue, 7 Jul 2020 02:02:37 +0300 Subject: chore: eslint stores feat: merge album and images --- src/site/store/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/site/store/index.js') diff --git a/src/site/store/index.js b/src/site/store/index.js index 8f910ae..c0faffb 100644 --- a/src/site/store/index.js +++ b/src/site/store/index.js @@ -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', { -- cgit v1.2.3