Просмотр исходного кода

:recycle: adjusting how single pages load hro

tags/0.9.0
J 4 лет назад
Родитель
Сommit
5f2927f149
2 измененных файлов: 12 добавлений и 11 удалений
  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 Просмотреть файл

@@ -166,6 +166,7 @@ export default {
166 166
          */
167 167
         checkAndSetHero(post) {
168 168
             if (!post) return
169
+            console.log('single hero...')
169 170
             let json = { url: post.featured, heroType: 'image' }
170 171
             if (
171 172
                 post.hero &&
@@ -209,21 +210,22 @@ export default {
209 210
             // Find the single post from api if it's not already in state
210 211
             // Then add it to our list
211 212
             
212
-            // if (!this[`all${type}Loaded`] && allPostsOfType.length < 1) {
213 213
             const res = await this.$store.dispatch(`getAll${type}`, { sortType: null, params: null})
214 214
             allPostsOfType = res
215
-            console.log(`reloaded ${type}...`)
216
-            // }
217 215
 
218 216
             const singlePostData = allPostsOfType.filter(
219 217
                 post => post.slug == this.$route.params.slug,
220 218
             )[0]
219
+
221 220
             if (!singlePostData) return
221
+
222 222
             // NOT plural
223
-            await this.$store.dispatch(
223
+            const post = await this.$store.dispatch(
224 224
                 `getSingle${convertTitleCase(this.type)}`,
225 225
                 singlePostData.id,
226 226
             )
227
+            
228
+            this.checkAndSetHero(this.singlePost)
227 229
         },
228 230
 
229 231
         scrollTo(hashtag) {
@@ -236,9 +238,9 @@ export default {
236 238
         post(newVal, oldVal) {
237 239
             // Prevent loading single post when
238 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 245
         $route(to, from) {
244 246
             // Only load post data when
@@ -253,9 +255,8 @@ export default {
253 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 262
 </script>

+ 1
- 1
vue-theme/src/store/modules/episode.js Просмотреть файл

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

Загрузка…
Отмена
Сохранить