Просмотр исходного кода

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

tags/0.9.0
J 4 лет назад
Родитель
Сommit
2288ca978e
1 измененных файлов: 26 добавлений и 27 удалений
  1. 26
    27
      vue-theme/src/pages/list.vue

+ 26
- 27
vue-theme/src/pages/list.vue Просмотреть файл

@@ -44,7 +44,8 @@ export default {
44 44
     data() {
45 45
         return {
46 46
             page: 0,
47
-            perPage: 9
47
+            perPage: 9,
48
+            keepFetching: true 
48 49
         }
49 50
     },
50 51
     computed: {
@@ -67,9 +68,10 @@ export default {
67 68
     },
68 69
     methods: {
69 70
         loadMorePosts() {
70
-            console.log(this.$route)
71
+            // console.log(this.$route)
71 72
             const type = typeFromRoute(this.$route)
72 73
             if(!type) return console.warn(`type: ${type} not found...`)
74
+            if(!keepFetching) return console.warn('nothing left to fetch...')
73 75
 
74 76
             console.warn(`loading more ${type} posts...`)
75 77
             this.page++
@@ -101,15 +103,33 @@ export default {
101 103
                 res = await this.$store.dispatch(dispatchAction, dispatchParams)
102 104
             }
103 105
 
106
+            // Stop trying to load more posts
104 107
             if(res && !res.length) {
105 108
                 console.warn('nothing left to get...')
109
+                this.keepFetching = false
106 110
             }
107 111
         },
108
-        clearHero() {
112
+        _clearHero() {
109 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 131
         async checkAndSetHero(type) {
112
-            this.clearHero()
132
+            this._clearHero()
113 133
 
114 134
             if (!this['allPagesLoaded']) {
115 135
                 await this.$store.dispatch('getAllPages', { sortType: null, params: null })
@@ -124,20 +144,7 @@ export default {
124 144
             )[0]
125 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 149
         setIntersectionLoader() {
143 150
             console.warn('setting up intersection handler for:', this.type)
@@ -166,20 +173,12 @@ export default {
166 173
             // Always reset the page count
167 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 179
     created() {
180 180
         console.log('--- liiiist ---')
181 181
         this.setIntersectionLoader()
182
-        // this.checkAndSetHero(this.type)
183 182
     },
184 183
 }
185 184
 </script>

Загрузка…
Отмена
Сохранить