|
|
@@ -33,7 +33,7 @@ import card from '@/components/card'
|
|
33
|
33
|
import sidebar from '@/components/sidebars/sidebar'
|
|
34
|
34
|
import { postTypeGetters, scrollTop, heroUtils } from './mixin-post-types'
|
|
35
|
35
|
|
|
36
|
|
-import { postTypes, sortTypes, convertTitleCase, typeFromRoute, sortFromRoute } from '@/utils/helpers'
|
|
|
36
|
+import { postTypes, sortTypes, convertTitleCase } from '@/utils/helpers'
|
|
37
|
37
|
|
|
38
|
38
|
const TIMEOUT = 1
|
|
39
|
39
|
const INTERSECT_SELECTOR = '.page--list > article footer'
|
|
|
@@ -84,40 +84,40 @@ export default {
|
|
84
|
84
|
if (!this.pType) return
|
|
85
|
85
|
return this[`all${this.pType}`]
|
|
86
|
86
|
},
|
|
|
87
|
+ shouldLoadAllAtOnce() {
|
|
|
88
|
+ return this.type == 'episode' || this.type == 'artist' && this.sortBy == sortTypes.material
|
|
|
89
|
+ }
|
|
87
|
90
|
},
|
|
88
|
91
|
methods: {
|
|
89
|
|
- clearAllPosts() {
|
|
90
|
|
- if(!this.type) return console.error(`post type: ${this.type} not found...`)
|
|
91
|
|
- this.$store.commit(`CLEAR_${this.pType.toUpperCase()}`)
|
|
92
|
|
- // this.$store.commit(`${this.type.toUpperCase()}S_LOADED`)
|
|
93
|
|
- },
|
|
94
|
|
- async loadMorePosts() {
|
|
|
92
|
+ async loadMorePosts(shouldClear) {
|
|
|
93
|
+ if(shouldClear) this.$store.commit(`CLEAR_${this.pType.toUpperCase()}`)
|
|
95
|
94
|
if(!this.keepFetching) return console.warn('nothing left to fetch...')
|
|
96
|
95
|
|
|
97
|
96
|
try {
|
|
98
|
97
|
this.loadingFetched = true
|
|
99
|
|
- // console.warn(`loading page ${this.page + 1} of ${type} posts: ${this.page * this.perPage + 1} to ${(this.page + 1) * this.perPage}`)
|
|
100
|
98
|
this.page++
|
|
101
|
|
- await this.getPosts()
|
|
|
99
|
+
|
|
|
100
|
+ const res = await this.getPosts(
|
|
|
101
|
+ {
|
|
|
102
|
+ limit: this.shouldLoadAllAtOnce ? -1 : this.perPage,
|
|
|
103
|
+ page: this.page
|
|
|
104
|
+ },
|
|
|
105
|
+ this.shouldLoadAllAtOnce ? 'All' : 'More'
|
|
|
106
|
+ )
|
|
|
107
|
+
|
|
102
|
108
|
this.loadingFetched = false
|
|
103
|
|
- } catch (err) {
|
|
104
|
|
- console.error(err)
|
|
105
|
|
- }
|
|
|
109
|
+
|
|
|
110
|
+ // Stop trying to load more posts
|
|
|
111
|
+ if(res && !res.length || this.shouldLoadAllAtOnce) {
|
|
|
112
|
+ this.keepFetching = false
|
|
|
113
|
+ if(!res.length) console.warn(`Empty response for ${this.type}:`, res.length)
|
|
|
114
|
+ if(this.shouldLoadAllAtOnce) console.warn(`Fetched all responses for ${this.type}:`, res.length)
|
|
|
115
|
+ }
|
|
|
116
|
+ } catch (err) { console.error(err) }
|
|
106
|
117
|
},
|
|
107
|
|
- async getPosts() {
|
|
|
118
|
+ async getPosts(params, dispatchType) {
|
|
108
|
119
|
if(!this.type) throw `post type: ${this.type} not found...`
|
|
109
|
|
-
|
|
110
|
|
- // Set some default dispatch paramters
|
|
111
|
|
- let dispatchType = 'More'
|
|
112
|
|
- let params = { limit: this.perPage, page: this.page }
|
|
113
|
120
|
|
|
114
|
|
- // For episodes, or material sort we grab EVERYTHING
|
|
115
|
|
- const getAllClause = this.type == 'episode' || this.type == 'artist' && this.sortBy == sortTypes.material
|
|
116
|
|
- if(getAllClause) {
|
|
117
|
|
- // dispatchType = 'All'
|
|
118
|
|
- params.limit = -1
|
|
119
|
|
- }
|
|
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') {
|
|
|
@@ -126,16 +126,10 @@ export default {
|
|
126
|
126
|
{ sortType: this.sortBy, params }
|
|
127
|
127
|
)
|
|
128
|
128
|
}
|
|
129
|
|
-
|
|
130
|
|
- // Stop trying to load more posts
|
|
131
|
|
- if(res && !res.length || getAllClause) {
|
|
132
|
|
- this.keepFetching = false
|
|
133
|
|
- if(!res.length) console.warn(`Empty response for ${this.type}:`, res.length)
|
|
134
|
|
- if(getAllClause) console.warn(`Fetched all responses for ${this.type}:`, res.length)
|
|
135
|
|
- }
|
|
|
129
|
+ return res
|
|
136
|
130
|
},
|
|
137
|
|
- async getPageForType(type) {
|
|
138
|
|
- await this._getAll('page', this.$store)
|
|
|
131
|
+ async getPage(type) {
|
|
|
132
|
+ await this._getAllIfNotLoaded('page', this.$store)
|
|
139
|
133
|
if(!this.allPages) throw 'no pages in state'
|
|
140
|
134
|
const page = this.allPages.filter(page => page.slug == `${type}s`)[0]
|
|
141
|
135
|
if(!page) throw `No page: ${type} found. Cannot set hero.`
|
|
|
@@ -146,7 +140,7 @@ export default {
|
|
146
|
140
|
async checkAndSetHero(type) {
|
|
147
|
141
|
this._clearHero(this.$store)
|
|
148
|
142
|
try {
|
|
149
|
|
- const page = await this.getPageForType(type)
|
|
|
143
|
+ const page = await this.getPage(type)
|
|
150
|
144
|
// We always set a hero no matter what
|
|
151
|
145
|
// Because the hero component will deal
|
|
152
|
146
|
// with how to render based on hero.url
|
|
|
@@ -178,21 +172,16 @@ export default {
|
|
178
|
172
|
if(!this.observer) throw `cannot unset intersection handler missing observer: ${this.observer}`
|
|
179
|
173
|
this.observer.unobserve(footerEl)
|
|
180
|
174
|
this.observer.disconnect()
|
|
181
|
|
- } catch (error) {
|
|
182
|
|
- console.error(error)
|
|
183
|
|
- }
|
|
|
175
|
+ } catch (error) { console.error(error) }
|
|
184
|
176
|
},
|
|
185
|
|
- clearAndInitPostList(caller) {
|
|
|
177
|
+ initPostList() {
|
|
186
|
178
|
this.page = 0
|
|
187
|
179
|
this.keepFetching = true
|
|
188
|
180
|
|
|
189
|
181
|
this.checkAndSetHero(this.type)
|
|
190
|
182
|
|
|
191
|
|
- // Fires when loading from home
|
|
192
|
183
|
// Clear any preloaded posts (from home, etc.)
|
|
193
|
|
- this.clearAllPosts()
|
|
194
|
|
- this.loadMorePosts()
|
|
195
|
|
-
|
|
|
184
|
+ this.loadMorePosts(true)
|
|
196
|
185
|
this.setIntersectionLoader()
|
|
197
|
186
|
}
|
|
198
|
187
|
},
|
|
|
@@ -206,16 +195,16 @@ export default {
|
|
206
|
195
|
// Ignore types with presorts so the sortBy watcher can handle them
|
|
207
|
196
|
const ignore = ['event', 'exhibition', 'artist']
|
|
208
|
197
|
if(ignore.includes(newType)) return
|
|
209
|
|
- this.clearAndInitPostList('type change')
|
|
|
198
|
+ this.initPostList()
|
|
210
|
199
|
},
|
|
211
|
200
|
sortBy(newSort) {
|
|
212
|
201
|
if(!Object.values(sortTypes).includes(newSort)) return
|
|
213
|
|
- this.clearAndInitPostList('sort change')
|
|
|
202
|
+ this.initPostList()
|
|
214
|
203
|
}
|
|
215
|
204
|
},
|
|
216
|
205
|
mounted() {
|
|
217
|
206
|
// This only fires navigating from a non-list page > list page
|
|
218
|
|
- this.clearAndInitPostList('mounted')
|
|
|
207
|
+ this.initPostList()
|
|
219
|
208
|
},
|
|
220
|
209
|
beforeDestroy() {
|
|
221
|
210
|
this.unsetIntersectionLoader()
|