瀏覽代碼

:bug: #51 | clearing and resetting hero for every page/post load

tags/0.9.0
J 4 年之前
父節點
當前提交
09f13f914b
共有 3 個文件被更改,包括 41 次插入14 次删除
  1. 21
    9
      vue-theme/src/components/hero.vue
  2. 6
    3
      vue-theme/src/pages/single.vue
  3. 14
    2
      vue-theme/src/store/index.js

+ 21
- 9
vue-theme/src/components/hero.vue 查看文件

@@ -1,14 +1,17 @@
1 1
 <template lang="pug">
2 2
 .hero.f-col(v-if="showHero")
3
-    iframe(
4
-        v-if="isPlaying"
5
-        :src="`https://www.youtube.com/embed/${heroIdFromUrl}?autoplay=1`"
6
-        frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope"
7
-        allowfullscreen
8
-    ).embedded
9
-    .blank.f-col(v-else)
10
-        h3(v-if="heroText") {{ heroText }}
11
-        button(v-if="showPlaybutton" @click="isPlaying = true") play
3
+    .hero--video(v-if="heroType === 'video'")
4
+        iframe(
5
+            v-if="isPlaying"
6
+            :src="`https://www.youtube.com/embed/${heroIdFromUrl}?autoplay=1`"
7
+            frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope"
8
+            allowfullscreen
9
+        ).embedded
10
+        .blank.f-col(v-else)
11
+            h3(v-if="heroText") {{ heroText }}
12
+            button(v-if="showPlaybutton" @click="isPlaying = true") play
13
+    .hero--image(v-else)
14
+        img(:src="showHero" alt="hero image")
12 15
 </template>
13 16
 
14 17
 <script>
@@ -25,9 +28,11 @@ export default {
25 28
         ...mapState({
26 29
             showHero: state => state.hero.url,
27 30
             heroText: state => state.hero.text,
31
+            heroType: state => state.hero.type,
28 32
             showPlaybutton: state => state.hero.playbutton,
29 33
         }),
30 34
         heroIdFromUrl() {
35
+            console.log()
31 36
             const url = this.showHero.split('/')
32 37
             return url.pop()
33 38
         }
@@ -42,7 +47,14 @@ export default {
42 47
         this.$nextTick(() => { window.addEventListener('resize', this.onResize) })
43 48
     },
44 49
     watch: {
50
+        $route() {
51
+            console.log('remounting hero')
52
+            console.log(this.$store)
53
+            // Clear the hero between pages
54
+            this.$store.commit('CLEAR_HERO')
55
+        },
45 56
         heroHeight() {
57
+            if(!this.showHero) return
46 58
             Object.assign(this.$el.style, {height: this.heroHeight + 'px'})
47 59
         }
48 60
     },

+ 6
- 3
vue-theme/src/pages/single.vue 查看文件

@@ -148,9 +148,12 @@ export default {
148 148
          * @param {object} posts
149 149
          */
150 150
         checkAndSetHero(post) {
151
-            if(!post || !post.hero) return
152
-
153
-            const json = JSON.parse(post.hero)
151
+            if(!post) return
152
+            const json = { url: post.featured, heroType: 'image' }
153
+            if(post.hero && JSON.parse(post.hero).url) {
154
+                json = JSON.parse(post.hero)
155
+                json.heroType = 'video'
156
+            }
154 157
             this.$store.commit('SET_HERO', json)
155 158
         },
156 159
 

+ 14
- 2
vue-theme/src/store/index.js 查看文件

@@ -20,7 +20,8 @@ const debug = process.env.NODE_ENV !== 'production'
20 20
 const state = {
21 21
     title: wp.site_name,
22 22
     hero: {
23
-        url: 'http://sample-image-url/',
23
+        url: null,
24
+        type: null,
24 25
         text: 'sample hero text',
25 26
         playbutton: true,
26 27
     },
@@ -31,13 +32,24 @@ const state = {
31 32
 const mutations = {
32 33
     SET_HERO(state, hero) {
33 34
         if (!hero) return
34
-
35
+        console.log(hero)
35 36
         if (hero.url) {
36 37
             state.hero.text = state.hero.url = hero.url
38
+            state.hero.type = hero.type
39
+
40
+            state.hero.playbutton = hero.type === 'video' ? true : false
37 41
         } else {
38 42
             state.hero.text = hero
39 43
         }
40 44
     },
45
+    CLEAR_HERO(state) {
46
+        state.hero = {
47
+            url: null,
48
+            type: null,
49
+            text: 'sample hero text',
50
+            playbutton: false,
51
+        }
52
+    },
41 53
     SET_GALLERY(state, idList) {
42 54
         state.gallery = idList
43 55
     },

Loading…
取消
儲存