Bläddra i källkod

:recycle: simplifying getPosts in list template

tags/0.9.0
J 4 år sedan
förälder
incheckning
df94073a4d
2 ändrade filer med 30 tillägg och 51 borttagningar
  1. 29
    48
      vue-theme/src/pages/list.vue
  2. 1
    3
      vue-theme/src/pages/single.vue

+ 29
- 48
vue-theme/src/pages/list.vue Visa fil

@@ -91,38 +91,19 @@ export default {
91 91
                       .filter(p => p)
92 92
                       .pop()
93 93
 
94
-            // Don't dispatch if there's no type
95
-            if (this.type && this.dispatchName && clear) {
96
-                this.$store.dispatch(
97
-                    this.dispatchName,
98
-                    { sortType: sort, params }
99
-                )
94
+            let dispatchParams = { sortType: sort, params }
95
+            let dispatchAction = this.dispatchName
100 96
 
101
-                if (this.type == 'event') {
102
-                    this.$store.dispatch(
103
-                        'getAllExhibitions',
104
-                        {
105
-                            sortType: sortTypes.currentAndUpcoming,
106
-                            params 
107
-                        }
108
-                    )
97
+            if(this.dispatchName && clear) {
98
+                if (this.type && ['event', 'exhibitions'].includes(this.type)) {
99
+                    dispatchParams.sortType = sortTypes.currentAndUpcoming
109 100
                 }
110
-                if (this.type == 'exhibition') {
111
-                    this.$store.dispatch(
112
-                        'getAllEvents',
113
-                        {
114
-                            sortType: sortTypes.currentAndUpcoming,
115
-                            params 
116
-                        }
117
-                    )
118
-                }
119
-            // Add to existing
120
-            } else if (!clear && this.getMoreName) {
121
-                this.$store.dispatch(
122
-                    this.getMoreName,
123
-                    { sortType: sort, params }
124
-                )
125 101
             }
102
+            // Add to existing except episodes
103
+            else if (!clear && this.getMoreName && this.type != 'episode') {
104
+                dispatchAction = this.getMoreName
105
+            }
106
+            this.$store.dispatch(dispatchAction, dispatchParams)
126 107
         },
127 108
         clearHero() {
128 109
             this.$store.commit('SET_HERO', { url: null, heroType: null })
@@ -143,22 +124,20 @@ export default {
143 124
             // Clear the hero and bail
144 125
             if(!page) return this.clearHero()
145 126
 
146
-            let hero = { url: page.featured, heroType:'image' }
127
+            let json = { url: page.featured, heroType:'image' }
147 128
             if (
148 129
                 page.hero &&
149 130
                 JSON.parse(page.hero) &&
150 131
                 JSON.parse(page.hero).url
151 132
             ) {
152
-                hero = JSON.parse(page.hero)
153
-                hero.heroType = 'video'
133
+                json = JSON.parse(page.hero)
134
+                heson.heroType = 'video'
154 135
             }
155 136
             // No featured or youTube
156
-            if (!hero.url) {
157
-                hero.heroType = null
158
-            }
137
+            if (!json.url) { json.heroType = null }
159 138
             // Set the hero text to the post title or excerpt
160
-            hero.text = page && page.excerpt ? page.excerpt : page.title
161
-            this.$store.commit('SET_HERO', hero)
139
+            json.text = page && page.excerpt ? page.excerpt : page.title
140
+            this.$store.commit('SET_HERO', json)
162 141
         },
163 142
         scrollTo(hashtag) {
164 143
             setTimeout(() => {
@@ -166,9 +145,10 @@ export default {
166 145
             }, TIMEOUT)
167 146
         },
168 147
         setIntersectionLoader() {
169
-            console.warn('setting up intersection handler...')
148
+            console.warn('setting up intersection handler...', this.type)
170 149
             window.removeEventListener("load", e => {}, false)
171 150
             const footerEl = document.querySelector(".footer-wrapper footer")
151
+            console.log('footer for intersection:', footerEl)
172 152
             if(!footerEl) return
173 153
             window.addEventListener("load", e => {
174 154
                 const observer = new IntersectionObserver(this.loadMorePosts, {
@@ -184,17 +164,18 @@ export default {
184 164
             // only grab the hero if moving to another list page
185 165
             // eg. list page -> list page
186 166
             const path = to.fullPath.split('/').filter(p => p)
187
-            if (path.length <= 1) {
188
-                this.clearHero()
189
-                this.checkAndSetHero(this.type)
190
-                
191
-                // TODO: Track last loaded page per post type
192
-                // Less http calls
193
-                this.page = 1
194
-                this.setIntersectionLoader()
195 167
 
196
-                this.getPosts(true)
197
-            }
168
+            // !:Only fires navigating TO list page
169
+            if (path.length > 1) return
170
+            
171
+            this.clearHero()
172
+            this.checkAndSetHero(this.type)
173
+            
174
+            // TODO: Track last loaded page per post type
175
+            // Less http calls
176
+            this.page = 1
177
+            this.setIntersectionLoader()
178
+            this.getPosts(true)
198 179
         },
199 180
     },
200 181
     mounted() {

+ 1
- 3
vue-theme/src/pages/single.vue Visa fil

@@ -181,9 +181,7 @@ export default {
181 181
                 json.heroType = 'video'
182 182
             }
183 183
             // No featured or youTube
184
-            if (!json.url) {
185
-                json.heroType = null
186
-            }
184
+            if (!json.url) { json.heroType = null }
187 185
             // Set the hero text to the post title
188 186
             json.text = post.title
189 187
             this.$store.commit('SET_HERO', json)

Laddar…
Avbryt
Spara