瀏覽代碼

:sparkles: added techniques vuex modules

tags/0.9.0
J 4 年之前
父節點
當前提交
259213c205
共有 2 個檔案被更改,包括 72 行新增0 行删除
  1. 2
    0
      vue-theme/src/store/index.js
  2. 70
    0
      vue-theme/src/store/modules/technique.js

+ 2
- 0
vue-theme/src/store/index.js 查看文件

@@ -12,6 +12,7 @@ import episode from './modules/episode'
12 12
 import event from './modules/event'
13 13
 import exhibition from './modules/exhibition'
14 14
 import short from './modules/short'
15
+import technique from './modules/technique'
15 16
 import guide from './modules/guide'
16 17
 import object from './modules/object'
17 18
 import publication from './modules/publication'
@@ -94,6 +95,7 @@ const store = new Vuex.Store({
94 95
         event,
95 96
         exhibition,
96 97
         short,
98
+        technique,
97 99
         guide,
98 100
         object,
99 101
         publication,

+ 70
- 0
vue-theme/src/store/modules/technique.js 查看文件

@@ -0,0 +1,70 @@
1
+import api from '../../utils/api'
2
+
3
+const state = {
4
+    all: [],
5
+    loaded: false,
6
+    singleTechnique: null,
7
+}
8
+
9
+const getters = {
10
+    allTechniques: state => state.all,
11
+    allTechniquesBySlug: state =>
12
+        Object.values(state.all).reduce((bySlug, technique) => {
13
+            bySlug[technique.slug] = technique
14
+            return bySlug
15
+        }, {}),
16
+    allTechniquesLoaded: state => state.loaded,
17
+}
18
+
19
+const actions = {
20
+    getAllTechniques({ commit }, { sortType, params }) {
21
+        commit('CLEAR_TECHNIQUES')
22
+        commit('TECHNIQUES_LOADED', false)
23
+        const storeFetch = (techniques => {
24
+            let repacked = techniques
25
+            commit('STORE_FETCHED_TECHNIQUES', { techniques: repacked })
26
+            commit('TECHNIQUES_LOADED', true)
27
+        })
28
+        return api.getByType({ type: 'technique', sort: sortType, params, cb: storeFetch })
29
+    },
30
+    getMoreTechniques({ commit }, { sortType, params }) {
31
+        const storeFetch = (techniques => {
32
+            let repacked = techniques
33
+            commit('ADD_TO_FETCHED_TECHNIQUES', { techniques: repacked })
34
+            commit('TECHNIQUES_LOADED', true)
35
+        })
36
+        return api.getByType({ type: 'technique', sort: sortType, params, cb: storeFetch })
37
+    },
38
+    getSingleTechnique({ commit }, id) {
39
+        commit('CLEAR_SINGLE_TECHNIQUES')
40
+        commit('TECHNIQUES_LOADED', false)
41
+
42
+        api.getSingleType('technique', id, technique => {
43
+            commit('STORE_FETCHED_SINGLE_TECHNIQUE', technique)
44
+            commit('TECHNIQUES_LOADED', true)
45
+        })
46
+    },
47
+}
48
+
49
+const mutations = {
50
+    ADD_TO_FETCHED_TECHNIQUES(state, { techniques }) {
51
+        state.all = [...state.all, ...techniques]
52
+    },
53
+    STORE_FETCHED_TECHNIQUES(state, { techniques }) {
54
+        state.all = techniques
55
+    },
56
+    STORE_FETCHED_SINGLE_TECHNIQUE(state, technique) {
57
+        state.singleTechnique = technique
58
+    },
59
+    CLEAR_TECHNIQUES(state) {
60
+        state.all = []
61
+    },
62
+    CLEAR_SINGLE_TECHNIQUES(state) {
63
+        state.singleTechnique = null
64
+    },
65
+    TECHNIQUES_LOADED(state, val) {
66
+        state.loaded = val
67
+    },
68
+}
69
+
70
+export default { state, getters, actions, mutations }

Loading…
取消
儲存