|
|
@@ -132,15 +132,19 @@ export default {
|
|
132
|
132
|
* !: posts watcher fires when this finishes
|
|
133
|
133
|
*/
|
|
134
|
134
|
let type = convertTitleCase(this.type)
|
|
135
|
|
- if(!this[`all${type}Loaded`] && type) {
|
|
|
135
|
+ let allPostsOfType = this.$store.state[dePluralize(this.type)].all
|
|
|
136
|
+
|
|
|
137
|
+ /**
|
|
|
138
|
+ * Load posts if they're not already in state
|
|
|
139
|
+ */
|
|
|
140
|
+ if(!this[`all${type}Loaded`] && allPostsOfType.length < 1) {
|
|
136
|
141
|
const res = await this.$store.dispatch(`getAll${type}`)
|
|
137
|
|
- const post = Object.values(res).filter(post => post.slug == this.$route.params.slug)[0]
|
|
138
|
|
- this.$store.dispatch(`getSingle${dePluralize(type)}`, post.id)
|
|
139
|
|
- } else {
|
|
140
|
|
- const post = Object.values(this.$store.state[this.type].all).filter(post => post.slug == this.$route.params.slug)[0]
|
|
141
|
|
- this.$store.dispatch(`getSingle${dePluralize(type)}`, post.id)
|
|
|
142
|
+ allPostsOfType = res
|
|
142
|
143
|
}
|
|
143
|
144
|
|
|
|
145
|
+ const single = Object.values(allPostsOfType).filter(post => post.slug == this.$route.params.slug)[0]
|
|
|
146
|
+ console.log(this.$route.params.slug)
|
|
|
147
|
+ this.$store.dispatch(`getSingle${dePluralize(type)}`, single.id)
|
|
144
|
148
|
}
|
|
145
|
149
|
}
|
|
146
|
150
|
</script>
|