Browse Source

bug: use type computer to fix episodes route edge case

tags/0.9.0
J 6 years ago
parent
commit
8dda00c706
2 changed files with 10 additions and 20 deletions
  1. 7
    12
      vue-theme/src/pages/list.vue
  2. 3
    8
      vue-theme/src/pages/single.vue

+ 7
- 12
vue-theme/src/pages/list.vue View File

2
 .page--list.f-row.between
2
 .page--list.f-row.between
3
     article.f-grow
3
     article.f-grow
4
         header
4
         header
5
-            h1 {{ site }}: {{ $route.params.type }} list
5
+            h1 {{ $route.params.type }} list
6
         section
6
         section
7
             h4 {{ $route.params.type }}
7
             h4 {{ $route.params.type }}
8
             p {{ Object.values(posts).length }}
8
             p {{ Object.values(posts).length }}
9
             p {{ sidebar }}
9
             p {{ sidebar }}
10
         section(v-for="post in posts")
10
         section(v-for="post in posts")
11
-            router-link(:to="`./${$route.params.type}/${post.slug}`")
11
+            router-link(:to="`./${type}/${post.slug}`")
12
                 h4 {{ post.title }}
12
                 h4 {{ post.title }}
13
     //- COMPONENT: Make this with a prop
13
     //- COMPONENT: Make this with a prop
14
     aside(v-if="sidebar").shadow.b-radius
14
     aside(v-if="sidebar").shadow.b-radius
34
             allEpisodes: 'allEpisodes',
34
             allEpisodes: 'allEpisodes',
35
             allEpisodesLoaded: 'allEpisodesLoaded',
35
             allEpisodesLoaded: 'allEpisodesLoaded',
36
         }),
36
         }),
37
+        type() { // Checks for type and fixes Episodes route edge case 
38
+            return this.$route.params.type ? this.$route.params.type : this.$route.fullPath.slice(1)
39
+        },
37
         posts() {
40
         posts() {
38
-            let type = this.$route.params.type ? this.$route.params.type : this.$route.fullPath.slice(1)
39
-            type = type.charAt(0).toUpperCase() + type.slice(1)
41
+            let type = this.type.charAt(0).toUpperCase() + this.type.slice(1)
40
             return this[`all${type}`]
42
             return this[`all${type}`]
41
         },
43
         },
42
     },
44
     },
43
-    data() {
44
-        return {
45
-            loaded: false,
46
-            site: wp.site_name,
47
-        }
48
-    },
49
     mounted() {
45
     mounted() {
50
-        let type = this.$route.params.type ? this.$route.params.type : this.$route.fullPath.slice(1)
51
-        type = type.charAt(0).toUpperCase() + type.slice(1)
46
+        let type = this.type.charAt(0).toUpperCase() + this.type.slice(1)
52
         this.$store.dispatch(`getAll${type}`)
47
         this.$store.dispatch(`getAll${type}`)
53
     }
48
     }
54
 }
49
 }

+ 3
- 8
vue-theme/src/pages/single.vue View File

35
             type = type.charAt(0).toUpperCase() + type.slice(1)
35
             type = type.charAt(0).toUpperCase() + type.slice(1)
36
 
36
 
37
             // Return list keyed by slug
37
             // Return list keyed by slug
38
-            return Object.values(this[`all${type}`]).reduce((acc, inc) => { 
39
-                acc[inc.slug] = inc
40
-                return acc
38
+            return Object.values(this[`all${type}`]).reduce((postsMap, post) => { 
39
+                postsMap[post.slug] = post
40
+                return postsMap
41
             }, {})
41
             }, {})
42
         },
42
         },
43
     },
43
     },
44
-    data() {
45
-        return {
46
-            loaded: false,
47
-        }
48
-    },
49
     mounted() {
44
     mounted() {
50
         // TODO: this should be conditional after checking vuex state
45
         // TODO: this should be conditional after checking vuex state
51
         let type = this.$route.params.type
46
         let type = this.$route.params.type

Loading…
Cancel
Save