Browse Source

:bug: fix for sort check

tags/0.9.0
J 4 years ago
parent
commit
3629ab138d
2 changed files with 15 additions and 15 deletions
  1. 7
    15
      vue-theme/src/pages/list.vue
  2. 8
    0
      vue-theme/src/utils/helpers.js

+ 7
- 15
vue-theme/src/pages/list.vue View File

33
 import sidebar from '@/components/sidebars/sidebar'
33
 import sidebar from '@/components/sidebars/sidebar'
34
 import { postTypeGetters, scrollTop, heroUtils } from './mixin-post-types'
34
 import { postTypeGetters, scrollTop, heroUtils } from './mixin-post-types'
35
 
35
 
36
-import { postTypes, sortTypes, convertTitleCase, typeFromRoute } from '@/utils/helpers'
36
+import { postTypes, sortTypes, convertTitleCase, typeFromRoute, sortFromRoute } from '@/utils/helpers'
37
 
37
 
38
 const TIMEOUT = 1
38
 const TIMEOUT = 1
39
 const INTERSECT_SELECTOR = '.page--list > article footer'
39
 const INTERSECT_SELECTOR = '.page--list > article footer'
98
         _getSortBy() {
98
         _getSortBy() {
99
             return this.sortBy
99
             return this.sortBy
100
                 ? this.sortBy
100
                 ? this.sortBy
101
-                : this.$route.path
102
-                      .split('/')
103
-                      .filter(p => p)
104
-                      .pop()
101
+                : sortFromRoute(this.$route)
105
         },
102
         },
106
         _getDispatchParams(perPage) {
103
         _getDispatchParams(perPage) {
107
             return {
104
             return {
210
         // and the post type has changed
207
         // and the post type has changed
211
         type(newType, oldType) {
208
         type(newType, oldType) {
212
             if(!postTypes.includes(newType)) return console.warn('type not found...')
209
             if(!postTypes.includes(newType)) return console.warn('type not found...')
213
-
214
             this.clearAndInitPostList('type watcher')
210
             this.clearAndInitPostList('type watcher')
215
         },
211
         },
216
         // Only fire if the sort type has changed
212
         // Only fire if the sort type has changed
217
         // and the post type is the same
213
         // and the post type is the same
214
+        // and both sorts are valid
218
         $route(to, from) {
215
         $route(to, from) {
219
-            const findSortBy = route => {
220
-                return route.sortBy ? route.sortBy : route.fullPath
221
-                    .split('/')
222
-                    .filter(p => p)
223
-                    .pop()
224
-            }
216
+            const validSorts = Object.values(sortTypes)
225
             if (
217
             if (
226
-                findSortBy(to) != findSortBy(from) &&
227
                 typeFromRoute(to) == typeFromRoute(from) &&
218
                 typeFromRoute(to) == typeFromRoute(from) &&
228
-                // Post slug sometimes appears as a sort
229
-                sortTypes.includes(findSortBy(to)) && sortTypes.includes(findSortBy(from))
219
+                sortFromRoute(to) != sortFromRoute(from) &&
220
+                // Post slug sometimes appears as a sort so we check it against known sorts
221
+                validSorts.includes(sortFromRoute(to)) && validSorts.includes(sortFromRoute(from))
230
             ) {
222
             ) {
231
                 this.clearAndInitPostList('$route watcher')
223
                 this.clearAndInitPostList('$route watcher')
232
             } 
224
             } 

+ 8
- 0
vue-theme/src/utils/helpers.js View File

54
     return type
54
     return type
55
 }
55
 }
56
 
56
 
57
+const sortFromRoute = route => {
58
+    return route.sortBy ? route.sortBy : route.fullPath
59
+        .split('/')
60
+        .filter(p => p)
61
+        .pop()
62
+}
63
+
57
 const ytThumbnail = (url, desiredSize) => {
64
 const ytThumbnail = (url, desiredSize) => {
58
     const remove = [
65
     const remove = [
59
         '',
66
         '',
97
     convertTitleCase,
104
     convertTitleCase,
98
     dePluralize,
105
     dePluralize,
99
     typeFromRoute,
106
     typeFromRoute,
107
+    sortFromRoute,
100
     sortTypes,
108
     sortTypes,
101
     postTypes,
109
     postTypes,
102
     ytThumbnail,
110
     ytThumbnail,

Loading…
Cancel
Save