Browse Source

:recycle: adjusting how single pages load hro

tags/0.9.0
J 4 years ago
parent
commit
5f2927f149
2 changed files with 12 additions and 11 deletions
  1. 11
    10
      vue-theme/src/pages/single.vue
  2. 1
    1
      vue-theme/src/store/modules/episode.js

+ 11
- 10
vue-theme/src/pages/single.vue View File

166
          */
166
          */
167
         checkAndSetHero(post) {
167
         checkAndSetHero(post) {
168
             if (!post) return
168
             if (!post) return
169
+            console.log('single hero...')
169
             let json = { url: post.featured, heroType: 'image' }
170
             let json = { url: post.featured, heroType: 'image' }
170
             if (
171
             if (
171
                 post.hero &&
172
                 post.hero &&
209
             // Find the single post from api if it's not already in state
210
             // Find the single post from api if it's not already in state
210
             // Then add it to our list
211
             // Then add it to our list
211
             
212
             
212
-            // if (!this[`all${type}Loaded`] && allPostsOfType.length < 1) {
213
             const res = await this.$store.dispatch(`getAll${type}`, { sortType: null, params: null})
213
             const res = await this.$store.dispatch(`getAll${type}`, { sortType: null, params: null})
214
             allPostsOfType = res
214
             allPostsOfType = res
215
-            console.log(`reloaded ${type}...`)
216
-            // }
217
 
215
 
218
             const singlePostData = allPostsOfType.filter(
216
             const singlePostData = allPostsOfType.filter(
219
                 post => post.slug == this.$route.params.slug,
217
                 post => post.slug == this.$route.params.slug,
220
             )[0]
218
             )[0]
219
+
221
             if (!singlePostData) return
220
             if (!singlePostData) return
221
+
222
             // NOT plural
222
             // NOT plural
223
-            await this.$store.dispatch(
223
+            const post = await this.$store.dispatch(
224
                 `getSingle${convertTitleCase(this.type)}`,
224
                 `getSingle${convertTitleCase(this.type)}`,
225
                 singlePostData.id,
225
                 singlePostData.id,
226
             )
226
             )
227
+            
228
+            this.checkAndSetHero(this.singlePost)
227
         },
229
         },
228
 
230
 
229
         scrollTo(hashtag) {
231
         scrollTo(hashtag) {
236
         post(newVal, oldVal) {
238
         post(newVal, oldVal) {
237
             // Prevent loading single post when
239
             // Prevent loading single post when
238
             // navigating AWAY from the page
240
             // navigating AWAY from the page
239
-            if (!oldVal) {
240
-                this.checkAndSetHero(newVal)
241
-            }
241
+            // if (!oldVal) {
242
+            //     this.checkAndSetHero(newVal)
243
+            // }
242
         },
244
         },
243
         $route(to, from) {
245
         $route(to, from) {
244
             // Only load post data when
246
             // Only load post data when
253
         //     setTimeout(() => this.scrollTo(this.$route.hash), TIMEOUT)
255
         //     setTimeout(() => this.scrollTo(this.$route.hash), TIMEOUT)
254
         // }
256
         // }
255
     },
257
     },
256
-    async created() {
257
-        await this.loadPostData()
258
-        this.checkAndSetHero(this.singlePost)
258
+    created() {
259
+       this.loadPostData()
259
     },
260
     },
260
 }
261
 }
261
 </script>
262
 </script>

+ 1
- 1
vue-theme/src/store/modules/episode.js View File

29
     getSingleEpisode({ commit }, id) {
29
     getSingleEpisode({ commit }, id) {
30
         commit('CLEAR_SINGLE_EPISODES')
30
         commit('CLEAR_SINGLE_EPISODES')
31
         commit('EPISODES_LOADED', false)
31
         commit('EPISODES_LOADED', false)
32
-        api.getSingleType('episode', id, episode => {
32
+        return api.getSingleType('episode', id, episode => {
33
             commit('STORE_FETCHED_SINGLE_EPISODE', episode)
33
             commit('STORE_FETCHED_SINGLE_EPISODE', episode)
34
             commit('EPISODES_LOADED', true)
34
             commit('EPISODES_LOADED', true)
35
         })
35
         })

Loading…
Cancel
Save