Selaa lähdekoodia

:recycle: refactoring hero json set | adding back intersection loader on watcher

tags/0.9.0
J 4 vuotta sitten
vanhempi
commit
2288ca978e
1 muutettua tiedostoa jossa 26 lisäystä ja 27 poistoa
  1. 26
    27
      vue-theme/src/pages/list.vue

+ 26
- 27
vue-theme/src/pages/list.vue Näytä tiedosto

44
     data() {
44
     data() {
45
         return {
45
         return {
46
             page: 0,
46
             page: 0,
47
-            perPage: 9
47
+            perPage: 9,
48
+            keepFetching: true 
48
         }
49
         }
49
     },
50
     },
50
     computed: {
51
     computed: {
67
     },
68
     },
68
     methods: {
69
     methods: {
69
         loadMorePosts() {
70
         loadMorePosts() {
70
-            console.log(this.$route)
71
+            // console.log(this.$route)
71
             const type = typeFromRoute(this.$route)
72
             const type = typeFromRoute(this.$route)
72
             if(!type) return console.warn(`type: ${type} not found...`)
73
             if(!type) return console.warn(`type: ${type} not found...`)
74
+            if(!keepFetching) return console.warn('nothing left to fetch...')
73
 
75
 
74
             console.warn(`loading more ${type} posts...`)
76
             console.warn(`loading more ${type} posts...`)
75
             this.page++
77
             this.page++
101
                 res = await this.$store.dispatch(dispatchAction, dispatchParams)
103
                 res = await this.$store.dispatch(dispatchAction, dispatchParams)
102
             }
104
             }
103
 
105
 
106
+            // Stop trying to load more posts
104
             if(res && !res.length) {
107
             if(res && !res.length) {
105
                 console.warn('nothing left to get...')
108
                 console.warn('nothing left to get...')
109
+                this.keepFetching = false
106
             }
110
             }
107
         },
111
         },
108
-        clearHero() {
112
+        _clearHero() {
109
             this.$store.commit('SET_HERO', { url: null, heroType: null })
113
             this.$store.commit('SET_HERO', { url: null, heroType: null })
110
         },
114
         },
115
+        _setHeroInfo(page) {
116
+            let json = { url: page.featured, heroType:'image' }
117
+            if (
118
+                page.hero &&
119
+                JSON.parse(page.hero) &&
120
+                JSON.parse(page.hero).url
121
+            ) {
122
+                json = JSON.parse(page.hero)
123
+                json.heroType = 'video'
124
+            }
125
+            // No featured or youTube
126
+            if (!json.url) { json.heroType = null }
127
+            // Set the hero text to the post title or excerpt
128
+            json.text = page && page.excerpt ? page.excerpt : page.title
129
+            return json
130
+        },
111
         async checkAndSetHero(type) {
131
         async checkAndSetHero(type) {
112
-            this.clearHero()
132
+            this._clearHero()
113
 
133
 
114
             if (!this['allPagesLoaded']) {
134
             if (!this['allPagesLoaded']) {
115
                 await this.$store.dispatch('getAllPages', { sortType: null, params: null })
135
                 await this.$store.dispatch('getAllPages', { sortType: null, params: null })
124
             )[0]
144
             )[0]
125
             if(!page) return console.warn(`no page for ${type} found`)
145
             if(!page) return console.warn(`no page for ${type} found`)
126
 
146
 
127
-            let json = { url: page.featured, heroType:'image' }
128
-            if (
129
-                page.hero &&
130
-                JSON.parse(page.hero) &&
131
-                JSON.parse(page.hero).url
132
-            ) {
133
-                json = JSON.parse(page.hero)
134
-                json.heroType = 'video'
135
-            }
136
-            // No featured or youTube
137
-            if (!json.url) { json.heroType = null }
138
-            // Set the hero text to the post title or excerpt
139
-            json.text = page && page.excerpt ? page.excerpt : page.title
140
-            this.$store.commit('SET_HERO', json)
147
+            this.$store.commit('SET_HERO', this._setHeroInfo(page))
141
         },
148
         },
142
         setIntersectionLoader() {
149
         setIntersectionLoader() {
143
             console.warn('setting up intersection handler for:', this.type)
150
             console.warn('setting up intersection handler for:', this.type)
166
             // Always reset the page count
173
             // Always reset the page count
167
             this.page = 0
174
             this.page = 0
168
             
175
             
169
-            // this.checkAndSetHero(this.type)
170
-            
171
-            // Load first page of results
172
-            // this.getPosts({ clear: false })
173
-            console.log("route", to, from)
174
-            // this.setIntersectionLoader()
176
+            this.setIntersectionLoader()
175
         },
177
         },
176
     },
178
     },
177
-    mounted() {
178
-    },
179
     created() {
179
     created() {
180
         console.log('--- liiiist ---')
180
         console.log('--- liiiist ---')
181
         this.setIntersectionLoader()
181
         this.setIntersectionLoader()
182
-        // this.checkAndSetHero(this.type)
183
     },
182
     },
184
 }
183
 }
185
 </script>
184
 </script>

Loading…
Peruuta
Tallenna