|
|
@@ -187,17 +187,34 @@ export default {
|
|
187
|
187
|
*/
|
|
188
|
188
|
// modules are NOT plural because module key
|
|
189
|
189
|
if (!this.$store.state[this.type]) return
|
|
|
190
|
+ let allPostsOfType = this.$store.state[this.type].all
|
|
190
|
191
|
|
|
|
192
|
+ /**
|
|
|
193
|
+ * Load posts if they're not already in state
|
|
|
194
|
+ */
|
|
|
195
|
+ // Find the single post from api if it's not already in state
|
|
|
196
|
+ // Then add it to our list
|
|
|
197
|
+ let singlePostData = allPostsOfType.filter(
|
|
|
198
|
+ post => post.slug == this.$route.params.slug,
|
|
|
199
|
+ )[0]
|
|
|
200
|
+
|
|
|
201
|
+ // Look if it exists before you try and load everything!
|
|
|
202
|
+ if(!singlePostData) {
|
|
|
203
|
+ const res = await this.$store.dispatch(`getAll${convertTitleCase(this.type)}s`, { sortType: null, params: null})
|
|
|
204
|
+ allPostsOfType = res
|
|
|
205
|
+ singlePostData = allPostsOfType.filter(
|
|
|
206
|
+ post => post.slug == this.$route.params.slug,
|
|
|
207
|
+ )[0]
|
|
|
208
|
+ }
|
|
|
209
|
+
|
|
|
210
|
+ if (!singlePostData) return console.error('could not get single post data...')
|
|
191
|
211
|
|
|
192
|
212
|
// NOT plural
|
|
193
|
|
- const singlePostData = await this.$store.dispatch(
|
|
|
213
|
+ this.checkAndSetHero(singlePostData)
|
|
|
214
|
+ await this.$store.dispatch(
|
|
194
|
215
|
`getSingle${convertTitleCase(this.type)}`,
|
|
195
|
216
|
singlePostData.id,
|
|
196
|
217
|
)
|
|
197
|
|
-
|
|
198
|
|
- if (!singlePostData) return console.error('could not get single post data...')
|
|
199
|
|
- this.checkAndSetHero(singlePostData)
|
|
200
|
|
-
|
|
201
|
218
|
this.loading = false
|
|
202
|
219
|
},
|
|
203
|
220
|
},
|