Procházet zdrojové kódy

:recycle: tweaking type pluralization

tags/0.9.0
J před 4 roky
rodič
revize
ab8c40876e
2 změnil soubory, kde provedl 18 přidání a 22 odebrání
  1. 15
    16
      vue-theme/src/pages/list.vue
  2. 3
    6
      vue-theme/src/pages/single.vue

+ 15
- 16
vue-theme/src/pages/list.vue Zobrazit soubor

@@ -52,23 +52,23 @@ export default {
52 52
             // Checks for type and fixes Episodes route edge case
53 53
             return typeFromRoute(this.$route)
54 54
         },
55
+        pType() {
56
+            const plural = this.type + 's'
57
+            return convertTitleCase(plural)
58
+        },
55 59
         dispatchName() {
56
-            let type = convertTitleCase(this.type) + 's'
57
-            return this.sortBy ? `getAll${type.split('/')[0]}` : `getAll${type}`
60
+            return this.sortBy ? `getAll${this.pType.split('/')[0]}` : `getAll${this.pType}`
58 61
         },
59 62
         getMoreName() {
60
-            let type = convertTitleCase(this.type) + 's'
61
-            return this.sortBy ? `getMore${type.split('/')[0]}` : `getMore${type}`
63
+            return this.sortBy ? `getMore${this.pType.split('/')[0]}` : `getMore${this.pType}`
62 64
         },
63 65
         loaded() {
64
-            let type = convertTitleCase(this.type) + 's'
65
-            if (!type) return
66
-            return this[`all${type}Loaded`]
66
+            if (!this.pType) return
67
+            return this[`all${this.pType}Loaded`]
67 68
         },
68 69
         posts() {
69
-            let type = convertTitleCase(this.type) + 's'
70
-            if (!type) return
71
-            return this[`all${type}`]
70
+            if (!this.pType) return
71
+            return this[`all${this.pType}`]
72 72
         },
73 73
     },
74 74
     methods: {
@@ -145,14 +145,14 @@ export default {
145 145
             }, TIMEOUT)
146 146
         },
147 147
         setIntersectionLoader() {
148
-            console.warn('setting up intersection handler...', this.type)
148
+            console.warn('setting up intersection handler for:', this.type)
149 149
             window.removeEventListener("load", e => {}, false)
150 150
             const footerEl = document.querySelector(".footer-wrapper footer")
151
-            console.log('footer for intersection:', footerEl)
152 151
             if(!footerEl) return
152
+
153 153
             window.addEventListener("load", e => {
154 154
                 const observer = new IntersectionObserver(this.loadMorePosts, {
155
-                    rootMargin: "0px 0px 20px 0px",
155
+                    rootMargin: "0px 0px -20px 0px",
156 156
                 })
157 157
                 observer.observe(footerEl)
158 158
             }, false)
@@ -185,12 +185,11 @@ export default {
185 185
         this.setIntersectionLoader()
186 186
     },
187 187
     created() {
188
-        let type = convertTitleCase(this.type) + 's'
189
-        this.checkAndSetHero(this.type)
188
+        this.checkAndSetHero(this.pType)
190 189
 
191 190
         // We also need to check if only ONE has been loaded because
192 191
         // coming from the homepage there will only be 1 item
193
-        if (!this[`all${type}Loaded`] || this[`all${type}`].length < 2) this.getPosts(true)
192
+        if (!this[`all${this.pType}Loaded`] || this[`all${this.pType}`].length < 2) this.getPosts(true)
194 193
     },
195 194
 }
196 195
 </script>

+ 3
- 6
vue-theme/src/pages/single.vue Zobrazit soubor

@@ -200,8 +200,6 @@ export default {
200 200
              * which is derived from the route
201 201
              * !: posts watcher fires when this finishes
202 202
              */
203
-            let type = convertTitleCase(this.type) + 's'
204
-
205 203
             // modules are NOT plural because module key
206 204
             if (!this.$store.state[this.type]) return
207 205
             let allPostsOfType = this.$store.state[this.type].all
@@ -217,7 +215,7 @@ export default {
217 215
 
218 216
             // Look if it exists before you try and load everything!
219 217
             if(!singlePostData) {
220
-                const res = await this.$store.dispatch(`getAll${type}`, { sortType: null, params: null})
218
+                const res = await this.$store.dispatch(`getAll${convertTitleCase(this.type)}s`, { sortType: null, params: null})
221 219
                 allPostsOfType = res
222 220
                 singlePostData = allPostsOfType.filter(
223 221
                     post => post.slug == this.$route.params.slug,
@@ -226,10 +224,9 @@ export default {
226 224
 
227 225
             if (!singlePostData) return
228 226
             
229
-            this.checkAndSetHero(singlePostData)
230
-
231 227
             // NOT plural
232
-            const post = await this.$store.dispatch(
228
+            this.checkAndSetHero(singlePostData)
229
+            await this.$store.dispatch(
233 230
                 `getSingle${convertTitleCase(this.type)}`,
234 231
                 singlePostData.id,
235 232
             )

Načítá se…
Zrušit
Uložit