From e5c10b520f3d50ab1ec0aed91bebc8242b8d7301 Mon Sep 17 00:00:00 2001 From: zeot Date: Wed, 12 Sep 2018 23:09:34 +0300 Subject: [PATCH] Server-side-rendering of categories --- front/client/components/Categories.vue | 78 +++++++++++++++----------- front/client/service/Category.ts | 21 +++++++ front/client/service/categories.ts | 21 ------- front/client/store/index.ts | 10 +++- front/client/store/modules/category.ts | 35 ++++++++++++ 5 files changed, 109 insertions(+), 56 deletions(-) create mode 100644 front/client/service/Category.ts delete mode 100644 front/client/service/categories.ts create mode 100644 front/client/store/modules/category.ts diff --git a/front/client/components/Categories.vue b/front/client/components/Categories.vue index 5517a3d..0cd9cc9 100644 --- a/front/client/components/Categories.vue +++ b/front/client/components/Categories.vue @@ -1,28 +1,35 @@ - \ No newline at end of file diff --git a/front/client/service/Category.ts b/front/client/service/Category.ts new file mode 100644 index 0000000..479c219 --- /dev/null +++ b/front/client/service/Category.ts @@ -0,0 +1,21 @@ +import axios from "axios"; + +class CategoryService { + async getCategoryList(): Promise { + const { data } = await axios.get("api/categories", {}) + return data + } +} + +export interface ICategory { + created: string + group: string + status: string + title: string + uid: string +} + +const categoryServiceInstance = new CategoryService() + + +export { categoryServiceInstance as CategoryService } diff --git a/front/client/service/categories.ts b/front/client/service/categories.ts deleted file mode 100644 index e7a9c60..0000000 --- a/front/client/service/categories.ts +++ /dev/null @@ -1,21 +0,0 @@ -import axios from "axios"; - -class CategoryService { - async getCategoriesList(): Promise { - const { data } = await axios.get("api/categories") - return data - } -} - -interface ICategory { - created: string - group: string - status: string - title: string - uid: string -} - -export { - CategoryService, - ICategory -} diff --git a/front/client/store/index.ts b/front/client/store/index.ts index b1c5c00..cb39f91 100644 --- a/front/client/store/index.ts +++ b/front/client/store/index.ts @@ -1,7 +1,15 @@ import Vuex from 'vuex' +import category from 'client/store/modules/category' -function createStore () { +function createStore() { + // TODO loggins mutations in dev return new Vuex.Store({ + state: {}, + actions: {}, + mutations: {}, + modules: { + category + } }) } diff --git a/front/client/store/modules/category.ts b/front/client/store/modules/category.ts new file mode 100644 index 0000000..24793e7 --- /dev/null +++ b/front/client/store/modules/category.ts @@ -0,0 +1,35 @@ +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 = {} + +const actions: ActionTree = { + async loadCategoryList({ commit }: ActionContext): Promise { + const data: ICategory[] = await CategoryService.getCategoryList() + commit('setCategoryList', data) + } +} + +const mutations: MutationTree = { + setCategoryList: (state: CategoryState, payload: ICategory[]) => { + state.categoryList = payload + } +} + +const category: Module = { + namespaced: true, + state, + getters, + actions, + mutations +}; + +export default category \ No newline at end of file