Преглед на файлове

:recycle: moving hero funcs to mixin | fixing fetch flag bug

tags/0.9.0
J преди 4 години
родител
ревизия
a3453232ad
променени са 3 файла, в които са добавени 31 реда и са изтрити 44 реда
  1. 5
    22
      vue-theme/src/pages/list.vue
  2. 21
    2
      vue-theme/src/pages/mixin-post-types.js
  3. 5
    20
      vue-theme/src/pages/single.vue

+ 5
- 22
vue-theme/src/pages/list.vue Целия файл

@@ -40,7 +40,7 @@ export default {
40 40
         grid: { type: Boolean },
41 41
         sortBy: { type: String },
42 42
     },
43
-    mixins: [postTypeGetters, scrollTop],
43
+    mixins: [postTypeGetters, scrollTop, heroUtils],
44 44
     data() {
45 45
         return {
46 46
             page: 0,
@@ -71,7 +71,7 @@ export default {
71 71
             // console.log(this.$route)
72 72
             const type = typeFromRoute(this.$route)
73 73
             if(!type) return console.warn(`type: ${type} not found...`)
74
-            if(!keepFetching) return console.warn('nothing left to fetch...')
74
+            if(!this.keepFetching) return console.warn('nothing left to fetch...')
75 75
 
76 76
             console.warn(`loading more ${type} posts...`)
77 77
             this.page++
@@ -109,27 +109,10 @@ export default {
109 109
                 this.keepFetching = false
110 110
             }
111 111
         },
112
-        _clearHero() {
113
-            this.$store.commit('SET_HERO', { url: null, heroType: null })
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
-        },
112
+        // _setHeroInfo(post) {} from mixin
113
+        // _clearHero(store) {} from mixin
131 114
         async checkAndSetHero(type) {
132
-            this._clearHero()
115
+            this._clearHero(this.$store)
133 116
 
134 117
             if (!this['allPagesLoaded']) {
135 118
                 await this.$store.dispatch('getAllPages', { sortType: null, params: null })

+ 21
- 2
vue-theme/src/pages/mixin-post-types.js Целия файл

@@ -41,5 +41,24 @@ const scrollTop = {
41 41
         window.scrollTo(0, 0)
42 42
     },
43 43
 }
44
-
45
-export { postTypeGetters, scrollTop }
44
+const heroUtils = {
45
+    methods: {
46
+        _setHeroInfo(post) {
47
+            let json = { url: post.featured, heroType:'image' }
48
+            if (
49
+                post.hero &&
50
+                JSON.parse(post.hero) &&
51
+                JSON.parse(post.hero).url
52
+            ) {
53
+                json = JSON.parse(post.hero)
54
+                json.heroType = 'video'
55
+            }
56
+            // No featured or youTube
57
+            if (!json.url) { json.heroType = null }
58
+            // Set the hero text to the post title or excerpt
59
+            json.text = post && post.excerpt ? post.excerpt : post.title
60
+            return json
61
+        },
62
+    }
63
+}
64
+export { postTypeGetters, scrollTop, heroUtils }

+ 5
- 20
vue-theme/src/pages/single.vue Целия файл

@@ -58,7 +58,7 @@ export default {
58 58
         sidebar: { type: Boolean },
59 59
         id: { type: Number },
60 60
     },
61
-    mixins: [postTypeGetters, scrollTop],
61
+    mixins: [postTypeGetters, scrollTop, heroUtils],
62 62
     data() {
63 63
         return {
64 64
             // Gallery control
@@ -159,9 +159,8 @@ export default {
159 159
         closeGallery() {
160 160
             this.activeGalleryIndex = this.activeImageID = -1
161 161
         },
162
-        clearHero() {
163
-            this.$store.commit('SET_HERO', { url: null, heroType: null })
164
-        },
162
+        // _setHeroInfo(post) {} from mixin
163
+        // _clearHero(store) {} from mixin
165 164
         /**
166 165
          * Everytime the posts object changes
167 166
          * we use this to set a new HERO
@@ -170,21 +169,7 @@ export default {
170 169
          */
171 170
         checkAndSetHero(post) {
172 171
             if (!post) return
173
-            console.log('single hero...')
174
-            let json = { url: post.featured, heroType: 'image' }
175
-            if (
176
-                post.hero &&
177
-                JSON.parse(post.hero) &&
178
-                JSON.parse(post.hero).url
179
-            ) {
180
-                json = JSON.parse(post.hero)
181
-                json.heroType = 'video'
182
-            }
183
-            // No featured or youTube
184
-            if (!json.url) { json.heroType = null }
185
-            // Set the hero text to the post title
186
-            json.text = post.title
187
-            this.$store.commit('SET_HERO', json)
172
+            this.$store.commit('SET_HERO', this._setHeroInfo(post))
188 173
         },
189 174
 
190 175
         /**
@@ -252,7 +237,7 @@ export default {
252 237
             //  navigating TO a single page
253 238
             const path = to.fullPath.split('/').filter(p => p)
254 239
             if (path.length > 1) {
255
-                this.clearHero()
240
+                this._clearHero(this.$store)
256 241
                 this.loadPostData()
257 242
             }
258 243
         },

Loading…
Отказ
Запис