|
|
@@ -85,22 +85,27 @@ export default {
|
|
85
|
85
|
}
|
|
86
|
86
|
},
|
|
87
|
87
|
clearAllPosts() {
|
|
88
|
|
- if(!this.type) return console.error(`type: ${this.type}...`)
|
|
89
|
|
- const uppercaseType = this.type.toUpperCase() + 'S'
|
|
90
|
|
- this.$store.commit(`CLEAR_${uppercaseType}`)
|
|
91
|
|
- this.$store.commit(`${uppercaseType}_LOADED`)
|
|
|
88
|
+ if(!this.type) return console.error(`post type: ${this.type} not found...`)
|
|
|
89
|
+ this.$store.commit(`CLEAR_${this.type.toUpperCase()}S`)
|
|
|
90
|
+ // this.$store.commit(`${this.type.toUpperCase()}S_LOADED`)
|
|
92
|
91
|
},
|
|
93
|
92
|
async loadMorePosts() {
|
|
94
|
|
- if(!this.type) return console.warn(`this.type: ${type} not found...`)
|
|
95
|
93
|
if(!this.keepFetching) return console.warn('nothing left to fetch...')
|
|
96
|
94
|
|
|
97
|
|
- this.loadingFetched = true
|
|
98
|
|
- // console.warn(`loading page ${this.page + 1} of ${type} posts: ${this.page * this.perPage + 1} to ${(this.page + 1) * this.perPage}`)
|
|
99
|
|
- this.page++
|
|
100
|
|
- await this.getPosts()
|
|
101
|
|
- this.loadingFetched = false
|
|
|
95
|
+ try {
|
|
|
96
|
+ this.loadingFetched = true
|
|
|
97
|
+ // console.warn(`loading page ${this.page + 1} of ${type} posts: ${this.page * this.perPage + 1} to ${(this.page + 1) * this.perPage}`)
|
|
|
98
|
+ this.page++
|
|
|
99
|
+ await this.getPosts()
|
|
|
100
|
+ this.loadingFetched = false
|
|
|
101
|
+ } catch (err) {
|
|
|
102
|
+ console.error(err)
|
|
|
103
|
+ }
|
|
102
|
104
|
},
|
|
103
|
105
|
async getPosts() {
|
|
|
106
|
+ if(!this.type) throw `post type: ${this.type} not found...`
|
|
|
107
|
+
|
|
|
108
|
+ // Set some default dispatch paramters
|
|
104
|
109
|
let dispatchAction = `getMore${this.pType}`
|
|
105
|
110
|
let params = this._getDispatchParams()
|
|
106
|
111
|
|
|
|
@@ -145,23 +150,19 @@ export default {
|
|
145
|
150
|
this.$store.commit('SET_HERO', this._setHeroInfo(page))
|
|
146
|
151
|
},
|
|
147
|
152
|
setIntersectionLoader() {
|
|
148
|
|
- if(!this.type) return console.error('cannot setup intersection handler for undefined type')
|
|
149
|
|
-
|
|
150
|
153
|
// KeepFetching is UNSET for certain post types and sort types in `loadMorePosts()`
|
|
151
|
154
|
if(!this.keepFetching) return console.warn('cannot setup intersection handler keepFetching is set false')
|
|
152
|
155
|
|
|
153
|
|
- console.warn('Setting interesection loader...')
|
|
154
|
|
-
|
|
155
|
|
- // Always unset and reset the intersection loader
|
|
|
156
|
+ // Always unset before setting the intersection loader
|
|
156
|
157
|
this.unsetIntersectionLoader()
|
|
157
|
158
|
|
|
158
|
|
- const onIntersect = (entries, observer) => {
|
|
|
159
|
+ console.warn('Setting interesection loader...')
|
|
|
160
|
+ this.observer = new IntersectionObserver(entries => {
|
|
159
|
161
|
entries.forEach(entry => {
|
|
160
|
162
|
if (!entry.isIntersecting || this.loadingFetched) return
|
|
161
|
|
- setTimeout(() => this.loadMorePosts(), TIMEOUT)
|
|
|
163
|
+ setTimeout(this.loadMorePosts, TIMEOUT)
|
|
162
|
164
|
})
|
|
163
|
|
- }
|
|
164
|
|
- this.observer = new IntersectionObserver(onIntersect, { threshold: 0.80 })
|
|
|
165
|
+ }, { threshold: 0.80 })
|
|
165
|
166
|
this.observer.observe(document.querySelector(INTERSECT_SELECTOR))
|
|
166
|
167
|
},
|
|
167
|
168
|
unsetIntersectionLoader() {
|
|
|
@@ -198,7 +199,8 @@ export default {
|
|
198
|
199
|
// and the post type has changed
|
|
199
|
200
|
type(newType, oldType) {
|
|
200
|
201
|
if(!postTypes.includes(newType)) return console.warn('type not valid...')
|
|
201
|
|
- this.clearAndInitPostList('type watcher')
|
|
|
202
|
+ // this.clearAndInitPostList('type watcher')
|
|
|
203
|
+ console.log('type watcher fired')
|
|
202
|
204
|
},
|
|
203
|
205
|
// Only fire if the sort type has changed
|
|
204
|
206
|
// and the post type is the same
|
|
|
@@ -211,7 +213,7 @@ export default {
|
|
211
|
213
|
// Post slug sometimes appears as a sort so we check it against known sorts
|
|
212
|
214
|
validSorts.includes(to.sortBy) && validSorts.includes(from.sortBy)
|
|
213
|
215
|
) {
|
|
214
|
|
- this.clearAndInitPostList('$route watcher')
|
|
|
216
|
+ console.log('$route watcher fired')
|
|
215
|
217
|
}
|
|
216
|
218
|
}
|
|
217
|
219
|
},
|