Pārlūkot izejas kodu

:recycle: init posts only on route change

tags/0.9.0
J 4 gadus atpakaļ
vecāks
revīzija
7f54be9a03
1 mainītis faili ar 16 papildinājumiem un 11 dzēšanām
  1. 16
    11
      vue-theme/src/pages/list.vue

+ 16
- 11
vue-theme/src/pages/list.vue Parādīt failu

195
             // Clear any preloaded posts (from home, etc.)
195
             // Clear any preloaded posts (from home, etc.)
196
             this.clearAllPosts()
196
             this.clearAllPosts()
197
             this.loadMorePosts()
197
             this.loadMorePosts()
198
+        },
199
+        routeInfoFromPath(fullPath) {
200
+            const [ potentialType, potentialSort ] = fullPath.split('/')
201
+            return {
202
+                sortBy: Object.values(sortTypes).includes(potentialSort) ? potentialSort : null,
203
+                type: postTypes.includes(potentialType) ? potentialType : null
204
+            }
198
         }
205
         }
199
     },
206
     },
200
     watch: {
207
     watch: {
202
         // a list page, to another list page
209
         // a list page, to another list page
203
         type(newType, oldType) {
210
         type(newType, oldType) {
204
             if(!postTypes.includes(newType)) return console.warn('type not found...')
211
             if(!postTypes.includes(newType)) return console.warn('type not found...')
205
-                
206
-            // this.setIntersectionLoader()
207
-            this.clearAndInitPostList()
212
+            // this.clearAndInitPostList()
208
         },
213
         },
209
         $route(to, from) {
214
         $route(to, from) {
210
-            // Reset the intersection loader if navigating AWAY from material sort page
211
-            console.log('---')
212
-            console.log('to :', to)
213
-            console.log('from :', from)
214
-            
215
+            // Always unset and reset the intersection loader
215
             this.unsetIntersectionLoader()
216
             this.unsetIntersectionLoader()
216
-            if(!to.fullPath.includes(sortTypes.material)) {
217
+            if(!toPathInfo.sortBy != sortTypes.material) {
217
                 this.setIntersectionLoader()
218
                 this.setIntersectionLoader()
218
             }
219
             }
219
-
220
-
220
+            console.log('---')
221
+            const toPathInfo = this.routeInfoFromPath(to.fullPath)
222
+            const fromPathInfo = this.routeInfoFromPath(from.fullPath)
223
+            console.log('to :', toPathInfo)
224
+            console.log('from :', fromPathInfo)
225
+            
221
             // Check if we changed sort method
226
             // Check if we changed sort method
222
             // from no sort to sorted
227
             // from no sort to sorted
223
             // or sorted to no sort
228
             // or sorted to no sort

Notiek ielāde…
Atcelt
Saglabāt