|
|
@@ -87,13 +87,24 @@ export default {
|
|
87
|
87
|
},
|
|
88
|
88
|
methods: {
|
|
89
|
89
|
async loadMorePosts(shouldClear) {
|
|
90
|
|
- if(shouldClear) this.$store.commit(`CLEAR_${this.pType.toUpperCase()}`)
|
|
91
|
|
- if(!this.keepFetching) return console.warn('nothing left to fetch...')
|
|
|
90
|
+ if(!this.keepFetching) return console.warn('Nothing left to fetch...')
|
|
|
91
|
+
|
|
|
92
|
+ const getPosts = async (params, dispatchType) => {
|
|
|
93
|
+ if(!this.type) throw `post type: ${this.type} not found...`
|
|
|
94
|
+ console.log('$route :', this.$route)
|
|
|
95
|
+ // We always grab all pages on hero init so no need to do it here
|
|
|
96
|
+ return this.pType && this.type != 'page' ? await this.$store.dispatch(
|
|
|
97
|
+ `get${dispatchType}${this.pType}`,
|
|
|
98
|
+ { sortType: this.sortBy, params }
|
|
|
99
|
+ ) : []
|
|
|
100
|
+ }
|
|
92
|
101
|
|
|
|
102
|
+ if(shouldClear) this.$store.commit(`CLEAR_${this.pType.toUpperCase()}`)
|
|
|
103
|
+ console.log('loadMore $route :', this.$route)
|
|
93
|
104
|
try {
|
|
94
|
105
|
this.loadingFetched = true
|
|
95
|
106
|
this.page++
|
|
96
|
|
- const res = await this.getPosts(
|
|
|
107
|
+ const res = await getPosts(
|
|
97
|
108
|
{
|
|
98
|
109
|
limit: this.shouldLoadAllAtOnce ? -1 : this.perPage,
|
|
99
|
110
|
page: this.page
|
|
|
@@ -110,19 +121,6 @@ export default {
|
|
110
|
121
|
}
|
|
111
|
122
|
} catch (err) { console.error(err) }
|
|
112
|
123
|
},
|
|
113
|
|
- async getPosts(params, dispatchType) {
|
|
114
|
|
- if(!this.type) throw `post type: ${this.type} not found...`
|
|
115
|
|
- let res = []
|
|
116
|
|
- console.log('$route :', this.$route)
|
|
117
|
|
- // We always grab all pages on hero init so no need to do it here
|
|
118
|
|
- if(this.pType && this.keepFetching && this.type != 'page') {
|
|
119
|
|
- res = await this.$store.dispatch(
|
|
120
|
|
- `get${dispatchType}${this.pType}`,
|
|
121
|
|
- { sortType: this.sortBy, params }
|
|
122
|
|
- )
|
|
123
|
|
- }
|
|
124
|
|
- return res
|
|
125
|
|
- },
|
|
126
|
124
|
async getPage(type) {
|
|
127
|
125
|
await this._getAllIfNotLoaded('page', this.$store)
|
|
128
|
126
|
if(!this.allPages) throw 'no pages in state'
|
|
|
@@ -163,8 +161,8 @@ export default {
|
|
163
|
161
|
unsetIntersectionLoader() {
|
|
164
|
162
|
const footerEl = document.querySelector(INTERSECT_SELECTOR)
|
|
165
|
163
|
try {
|
|
166
|
|
- if(!footerEl) throw `cannot unset intersection handler missing el: ${footerEl}`
|
|
167
|
|
- if(!this.observer) throw `cannot unset intersection handler missing observer: ${this.observer}`
|
|
|
164
|
+ if(!footerEl) throw `Cannot unset intersection handler missing el: ${footerEl}`
|
|
|
165
|
+ if(!this.observer) return
|
|
168
|
166
|
this.observer.unobserve(footerEl)
|
|
169
|
167
|
this.observer.disconnect()
|
|
170
|
168
|
} catch (error) { console.error(error) }
|