Pārlūkot izejas kodu

:recycle: fixing single route watch

tags/0.9.0
J 4 gadus atpakaļ
vecāks
revīzija
69608452d7
2 mainītis faili ar 12 papildinājumiem un 13 dzēšanām
  1. 8
    10
      vue-theme/src/pages/list.vue
  2. 4
    3
      vue-theme/src/pages/single.vue

+ 8
- 10
vue-theme/src/pages/list.vue Parādīt failu

@@ -108,20 +108,23 @@ export default {
108 108
             if(!this.type) throw `post type: ${this.type} not found...`
109 109
 
110 110
             // Set some default dispatch paramters
111
-            let dispatchAction = 'More'
111
+            let dispatchType = 'More'
112 112
             let params = { limit: this.perPage, page: this.page }
113 113
             
114 114
             // For episodes, or material sort we grab EVERYTHING
115 115
             const getAllClause = this.type == 'episode' || this.type == 'artist' && this.sortBy == sortTypes.material
116 116
             if(getAllClause) {
117
-                dispatchAction = 'All'
117
+                // dispatchType = 'All'
118 118
                 params.limit = -1
119 119
             }
120 120
 
121 121
             let res = []
122 122
             // We always grab all pages on hero init so no need to do it here
123 123
             if(this.pType && this.keepFetching && this.type != 'page') {
124
-                res = await this.$store.dispatch(`get${dispatchAction}${this.pType}`, { sortType: this.sortBy, params })
124
+                res = await this.$store.dispatch(
125
+                    `get${dispatchType}${this.pType}`,
126
+                    { sortType: this.sortBy, params }
127
+                )
125 128
             }
126 129
 
127 130
             // Stop trying to load more posts
@@ -203,20 +206,15 @@ export default {
203 206
             // Ignore types with presorts so the sortBy watcher can handle them
204 207
             const ignore = ['event', 'exhibition', 'artist']
205 208
             if(ignore.includes(newType)) return
206
-            
207 209
             this.clearAndInitPostList('type change')
208 210
         },
209 211
         sortBy(newSort) {
210
-            if(Object.values(sortTypes).includes(newSort)) {
211
-                this.clearAndInitPostList('sort change')
212
-            }
212
+            if(!Object.values(sortTypes).includes(newSort)) return
213
+            this.clearAndInitPostList('sort change')
213 214
         }
214 215
     },
215 216
     mounted() {
216 217
         // This only fires navigating from a non-list page > list page
217
-        console.log(this.$route)
218
-        console.log(this.type)
219
-        console.log(this.sortBy)
220 218
         this.clearAndInitPostList('mounted')
221 219
     },
222 220
     beforeDestroy() {

+ 4
- 3
vue-theme/src/pages/single.vue Parādīt failu

@@ -199,7 +199,7 @@ export default {
199 199
                 console.warn('Could not find single post in store; Fetching everything...')
200 200
                 const res = await this.$store.dispatch(
201 201
                     `getAll${convertTitleCase(this.type)}s`,
202
-                    { sortType: null, params: null}
202
+                    { sortType: null, params: null }
203 203
                 )
204 204
                 singlePostData = res.filter(
205 205
                     post => post.slug == this.$route.params.slug,
@@ -223,10 +223,11 @@ export default {
223 223
     },
224 224
     watch: {
225 225
         // This fires navigating to and away
226
-        $route(to, from) {
226
+        $route(to) {
227 227
             // Only load post data when navigating TO a single page
228 228
             const path = to.fullPath.split('/').filter(p => p)
229
-            if (path.length < 2 || !postTypes.includes(to.params.type)) return
229
+            console.log('single to :', to)
230
+            if (path.length < 2 || !postTypes.includes(to.params.type) || !to.params.sortBy) return
230 231
             this._clearHero(this.$store)
231 232
             this.loadPostData()
232 233
         },

Notiek ielāde…
Atcelt
Saglabāt