mirror of
https://github.com/r-ca/kidshift-web.git
synced 2024-10-26 00:34:01 +00:00
parent
aad9ec4251
commit
5a1af1e7c9
|
@ -1,23 +0,0 @@
|
|||
import { ActionTree } from 'vuex';
|
||||
import { UserState, Task } from './types';
|
||||
import { StateInterface } from '../index';
|
||||
|
||||
const actions: ActionTree<UserState, StateInterface> = {
|
||||
updateToken({ commit }, token: string) {
|
||||
commit('setToken', token);
|
||||
},
|
||||
updateUsername({ commit }, username: string) {
|
||||
commit('setUsername', username);
|
||||
},
|
||||
updateTaskList({ commit }, taskList: Task[]) {
|
||||
commit('setTaskList', taskList);
|
||||
},
|
||||
addTask({ commit }, task: Task) {
|
||||
commit('addTask', task);
|
||||
},
|
||||
completeTask({ commit }, taskId: number) {
|
||||
commit('completeTask', taskId);
|
||||
},
|
||||
};
|
||||
|
||||
export default actions;
|
|
@ -1,19 +0,0 @@
|
|||
import { MutationTree } from 'vuex';
|
||||
import { UserState, Task } from './types';
|
||||
|
||||
const mutations: MutationTree<UserState> = {
|
||||
setToken(state, token: string) {
|
||||
state.token = token;
|
||||
},
|
||||
setUsername(state, username: string) {
|
||||
state.username = username;
|
||||
},
|
||||
setTaskList(state, taskList: Task[]) {
|
||||
state.taskList = taskList;
|
||||
},
|
||||
addTask(state, task: Task) {
|
||||
state.taskList.push(task);
|
||||
},
|
||||
};
|
||||
|
||||
export default mutations;
|
|
@ -1,9 +0,0 @@
|
|||
import { UserState } from './types';
|
||||
|
||||
const state: UserState = {
|
||||
token: '',
|
||||
username: '',
|
||||
taskList: [],
|
||||
};
|
||||
|
||||
export default state;
|
|
@ -1,11 +0,0 @@
|
|||
export interface Task {
|
||||
id: string;
|
||||
name: string;
|
||||
reward: number;
|
||||
}
|
||||
|
||||
export interface UserState {
|
||||
token: string;
|
||||
username: string;
|
||||
taskList: Task[];
|
||||
}
|
|
@ -1,39 +1,61 @@
|
|||
import { store } from 'quasar/wrappers';
|
||||
import { InjectionKey } from 'vue';
|
||||
import { createStore, Store as VuexStore, useStore as vuexUseStore } from 'vuex';
|
||||
import user from './accountState';
|
||||
import { UserState } from './user/types';
|
||||
import { store } from 'quasar/wrappers'
|
||||
import { InjectionKey } from 'vue'
|
||||
import { Router } from 'vue-router'
|
||||
import {
|
||||
createStore,
|
||||
Store as VuexStore,
|
||||
useStore as vuexUseStore,
|
||||
} from 'vuex'
|
||||
|
||||
export interface StateInterface {
|
||||
user: UserState;
|
||||
// import example from './module-example'
|
||||
// import { ExampleStateInterface } from './module-example/state';
|
||||
|
||||
/*
|
||||
* If not building with SSR mode, you can
|
||||
* directly export the Store instantiation;
|
||||
*
|
||||
* The function below can be async too; either use
|
||||
* async/await or return a Promise which resolves
|
||||
* with the Store instance.
|
||||
*/
|
||||
|
||||
export interface AccountStateInterface {
|
||||
account: {
|
||||
username: string
|
||||
token: string
|
||||
}
|
||||
isLogin: boolean
|
||||
taskList: any[]
|
||||
}
|
||||
|
||||
// Provide typings for `this.$store`
|
||||
// provide typings for `this.$store`
|
||||
declare module '@vue/runtime-core' {
|
||||
interface ComponentCustomProperties {
|
||||
$store: VuexStore<StateInterface>;
|
||||
$store: VuexStore<AccountStateInterface>
|
||||
}
|
||||
}
|
||||
|
||||
// Provide typings for `useStore` helper
|
||||
export const storeKey: InjectionKey<VuexStore<StateInterface>> = Symbol('vuex-key');
|
||||
// provide typings for `useStore` helper
|
||||
export const storeKey: InjectionKey<VuexStore<AccountStateInterface>> = Symbol('vuex-key')
|
||||
|
||||
// Provide typings for `this.$router` inside Vuex stores
|
||||
declare module 'vuex' {
|
||||
declare module "vuex" {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export interface Store<S> {
|
||||
readonly $router: Router;
|
||||
}
|
||||
}
|
||||
|
||||
export default store(function() {
|
||||
const Store = createStore<StateInterface>({
|
||||
modules: {
|
||||
user,
|
||||
},
|
||||
plugins: [createPersistedState({
|
||||
paths: ['user.token', 'user.username', 'user.taskList'],
|
||||
})],
|
||||
});
|
||||
export default store(function(/* { ssrContext } */) {
|
||||
const Store = createStore<AccountStateInterface>({
|
||||
// enable strict mode (adds overhead!)
|
||||
// for dev mode and --debug builds only
|
||||
strict: !!process.env.DEBUGGING
|
||||
})
|
||||
|
||||
return Store;
|
||||
});
|
||||
})
|
||||
|
||||
export function useStore() {
|
||||
return vuexUseStore(storeKey)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user