|
|
@@ -187,34 +187,17 @@ 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
|
|
191
|
190
|
|
|
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
|
|
211
|
191
|
|
|
212
|
192
|
// NOT plural
|
|
213
|
|
- this.checkAndSetHero(singlePostData)
|
|
214
|
|
- await this.$store.dispatch(
|
|
|
193
|
+ const singlePostData = await this.$store.dispatch(
|
|
215
|
194
|
`getSingle${convertTitleCase(this.type)}`,
|
|
216
|
195
|
singlePostData.id,
|
|
217
|
196
|
)
|
|
|
197
|
+
|
|
|
198
|
+ if (!singlePostData) return console.error('could not get single post data...')
|
|
|
199
|
+ this.checkAndSetHero(singlePostData)
|
|
|
200
|
+
|
|
218
|
201
|
this.loading = false
|
|
219
|
202
|
},
|
|
220
|
203
|
},
|