1
1
mirror of https://github.com/aelve/guide.git synced 2024-12-26 14:23:14 +03:00
guide/front/client/store/modules/category.ts

43 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-09-13 10:51:20 +03:00
import { ActionTree, GetterTree, MutationTree, ActionContext, Module } from 'vuex'
import { ICategory, CategoryService } from 'client/service/Category'
interface CategoryState {
categoryList: ICategory[]
}
const state: CategoryState = {
categoryList: []
}
const getters: GetterTree<CategoryState, any> = {}
const actions: ActionTree<CategoryState, any> = {
async loadCategoryList({ commit }: ActionContext<CategoryState, any>): Promise<any> {
const data: ICategory[] = await CategoryService.getCategoryList()
commit('setCategoryList', data)
2018-10-29 21:17:13 +03:00
},
async createCategory({ dispatch }, { title, group }: ICategory): Promise<ICategory['uid']> {
const createdId = await CategoryService.createCategory({
title,
group
})
dispatch('loadCategoryList')
return createdId
2018-09-13 10:51:20 +03:00
}
}
const mutations: MutationTree<CategoryState> = {
setCategoryList: (state: CategoryState, payload: ICategory[]) => {
state.categoryList = payload
}
}
const category: Module<CategoryState, any> = {
namespaced: true,
state,
getters,
actions,
mutations
};
export default category