Ver código fonte

:recycle: limiting hero load in route watcher

tags/0.9.0
J 4 anos atrás
pai
commit
cf7ebe954a
2 arquivos alterados com 14 adições e 7 exclusões
  1. 10
    7
      vue-theme/src/pages/list.vue
  2. 4
    0
      vue-theme/src/pages/single.vue

+ 10
- 7
vue-theme/src/pages/list.vue Ver arquivo

130
                 )
130
                 )
131
             }
131
             }
132
         },
132
         },
133
+        clearHero() {
134
+            this.$store.commit('SET_HERO', { url: null, heroType: null })
135
+        },
133
         async checkAndSetHero(type) {
136
         async checkAndSetHero(type) {
134
             if (!this['allPagesLoaded']) {
137
             if (!this['allPagesLoaded']) {
135
                 await this.$store.dispatch('getAllPages', { sortType: null, params: null })
138
                 await this.$store.dispatch('getAllPages', { sortType: null, params: null })
143
                 page => page.slug == type + 's',
146
                 page => page.slug == type + 's',
144
             )[0]
147
             )[0]
145
 
148
 
146
-            let hero = { url: null, heroType: null }
147
 
149
 
148
             // Clear the hero and bail
150
             // Clear the hero and bail
149
-            if(!page) return this.$store.commit('SET_HERO', hero)
151
+            if(!page) return this.clearHero()
150
 
152
 
151
             console.log('setting hero:', page)
153
             console.log('setting hero:', page)
152
-            hero.url = page.featured
153
-            hero.heroType = 'image'
154
+            let hero = { url: page.featured, heroType:'image' }
154
             if (
155
             if (
155
                 page.hero &&
156
                 page.hero &&
156
                 JSON.parse(page.hero) &&
157
                 JSON.parse(page.hero) &&
187
     },
188
     },
188
     watch: {
189
     watch: {
189
         $route(to, from) {
190
         $route(to, from) {
190
-            console.log('to:', to)
191
-            console.log('from:', from)
192
-            this.checkAndSetHero(this.type)
191
+            // Only grab the hero if moving to another list page
192
+            if (to.fullPath.split('/').filter(p => p).length < 1) {
193
+                this.clearHero()
194
+                this.checkAndSetHero(this.type)
195
+            }
193
 
196
 
194
             let sort = to.path
197
             let sort = to.path
195
                 .split('/')
198
                 .split('/')

+ 4
- 0
vue-theme/src/pages/single.vue Ver arquivo

159
         closeGallery() {
159
         closeGallery() {
160
             this.activeGalleryIndex = this.activeImageID = -1
160
             this.activeGalleryIndex = this.activeImageID = -1
161
         },
161
         },
162
+        clearHero() {
163
+            this.$store.commit('SET_HERO', { url: null, heroType: null })
164
+        },
162
         /**
165
         /**
163
          * Everytime the posts object changes
166
          * Everytime the posts object changes
164
          * we use this to set a new HERO
167
          * we use this to set a new HERO
256
             // Only load post data when
259
             // Only load post data when
257
             //  navigating TO a single page
260
             //  navigating TO a single page
258
             if (to.fullPath.split('/').filter(p => p).length > 1) {
261
             if (to.fullPath.split('/').filter(p => p).length > 1) {
262
+                this.clearHero()
259
                 this.loadPostData()
263
                 this.loadPostData()
260
             }
264
             }
261
         },
265
         },

Carregando…
Cancelar
Salvar