Browse Source

:recycle: a little refactor of dispatching from index | moving post type list to helper | guarding against an error in list

tags/0.9.0
j 5 years ago
parent
commit
a3a7884775

+ 6
- 8
vue-theme/src/pages/index.vue View File

@@ -33,19 +33,17 @@
33 33
 <script>
34 34
 import { postTypeGetters } from './mixin-post-types'
35 35
 
36
+import { convertTitleCase, postTypes } from '@/utils/helpers'
37
+
36 38
 export default {
37 39
     mixins: [postTypeGetters],
38 40
     created() {
39 41
         console.log(wp)
40
-        console.log(this.$store.state.title)
41
-
42
-        this.$store.dispatch('getAllPages')
43
-        this.$store.dispatch('getAllPosts')
44 42
 
45
-        this.$store.dispatch('getAllArtists')
46
-        this.$store.dispatch('getAllEpisodes')
47
-        this.$store.dispatch('getAllEvents')
48
-        this.$store.dispatch('getAllExhibitions')
43
+        postTypes.forEach(type => {
44
+            const capitalizedType = convertTitleCase(type)
45
+            this.$store.dispatch(`getAll${capitalizedType}`)
46
+        })
49 47
     }
50 48
 }
51 49
 </script>

+ 6
- 3
vue-theme/src/pages/list.vue View File

@@ -74,7 +74,10 @@ export default {
74 74
 
75 75
             // Seperate sorting from post slugs
76 76
             if(!this.sortBy || Object.values(sortTypes).indexOf(this.sortBy) >= 0) { 
77
-                this.$store.dispatch(this.dispatchName, this.sortBy)
77
+                // Don't dispatch if there's no type
78
+                if(this.type) {
79
+                    this.$store.dispatch(this.dispatchName, this.sortBy)
80
+                }
78 81
             }
79 82
             if(this.$store.state.hero.url !== type) this.$store.commit('SET_HERO', type)
80 83
         }
@@ -87,8 +90,8 @@ export default {
87 90
     },
88 91
     created() {
89 92
         let type = convertTitleCase(this.type)
90
-        console.log('already loaded ?:', this[`all${type}Loaded`])
91
-        console.log(this)
93
+        // console.log('already loaded ?:', this[`all${type}Loaded`])
94
+        
92 95
         if(!this[`all${type}Loaded`]) this.setHeroAndGetPosts()
93 96
     }
94 97
 }

+ 1
- 14
vue-theme/src/pages/mixin-post-types.js View File

@@ -1,18 +1,5 @@
1
-import { convertTitleCase } from '@/utils/helpers'
1
+import { convertTitleCase, postTypes } from '@/utils/helpers'
2 2
 import { mapGetters, mapState } from 'vuex'
3
-/**
4
- * A list of custom post types used to dispatch vuex actions
5
- * This makes ALL post type modules available for the
6
- * list and single components to request data
7
- */
8
-const postTypes = [
9
-    'posts',
10
-    'pages',
11
-    'artists',
12
-    'episodes',
13
-    'events',
14
-    'exhibitions'
15
-]
16 3
 
17 4
 /**
18 5
  * Create an object to hold the action names

+ 15
- 1
vue-theme/src/utils/helpers.js View File

@@ -18,4 +18,18 @@ const sortTypes = {
18 18
     material: 'by-material',
19 19
 }
20 20
 
21
-export { convertTitleCase, dePluralize, typeFromRoute, sortTypes }
21
+/**
22
+ * A list of custom post types used to dispatch vuex actions
23
+ * This makes ALL post type modules available for the
24
+ * list and single components to request data
25
+ */
26
+ const postTypes = [
27
+    'posts',
28
+    'pages',
29
+    'artists',
30
+    'episodes',
31
+    'events',
32
+    'exhibitions'
33
+]
34
+
35
+export { convertTitleCase, dePluralize, typeFromRoute, sortTypes, postTypes }

Loading…
Cancel
Save