Переглянути джерело

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

tags/0.9.0
J 4 роки тому
джерело
коміт
09f13f914b

+ 21
- 9
vue-theme/src/components/hero.vue Переглянути файл

1
 <template lang="pug">
1
 <template lang="pug">
2
 .hero.f-col(v-if="showHero")
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
 </template>
15
 </template>
13
 
16
 
14
 <script>
17
 <script>
25
         ...mapState({
28
         ...mapState({
26
             showHero: state => state.hero.url,
29
             showHero: state => state.hero.url,
27
             heroText: state => state.hero.text,
30
             heroText: state => state.hero.text,
31
+            heroType: state => state.hero.type,
28
             showPlaybutton: state => state.hero.playbutton,
32
             showPlaybutton: state => state.hero.playbutton,
29
         }),
33
         }),
30
         heroIdFromUrl() {
34
         heroIdFromUrl() {
35
+            console.log()
31
             const url = this.showHero.split('/')
36
             const url = this.showHero.split('/')
32
             return url.pop()
37
             return url.pop()
33
         }
38
         }
42
         this.$nextTick(() => { window.addEventListener('resize', this.onResize) })
47
         this.$nextTick(() => { window.addEventListener('resize', this.onResize) })
43
     },
48
     },
44
     watch: {
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
         heroHeight() {
56
         heroHeight() {
57
+            if(!this.showHero) return
46
             Object.assign(this.$el.style, {height: this.heroHeight + 'px'})
58
             Object.assign(this.$el.style, {height: this.heroHeight + 'px'})
47
         }
59
         }
48
     },
60
     },

+ 6
- 3
vue-theme/src/pages/single.vue Переглянути файл

148
          * @param {object} posts
148
          * @param {object} posts
149
          */
149
          */
150
         checkAndSetHero(post) {
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
             this.$store.commit('SET_HERO', json)
157
             this.$store.commit('SET_HERO', json)
155
         },
158
         },
156
 
159
 

+ 14
- 2
vue-theme/src/store/index.js Переглянути файл

20
 const state = {
20
 const state = {
21
     title: wp.site_name,
21
     title: wp.site_name,
22
     hero: {
22
     hero: {
23
-        url: 'http://sample-image-url/',
23
+        url: null,
24
+        type: null,
24
         text: 'sample hero text',
25
         text: 'sample hero text',
25
         playbutton: true,
26
         playbutton: true,
26
     },
27
     },
31
 const mutations = {
32
 const mutations = {
32
     SET_HERO(state, hero) {
33
     SET_HERO(state, hero) {
33
         if (!hero) return
34
         if (!hero) return
34
-
35
+        console.log(hero)
35
         if (hero.url) {
36
         if (hero.url) {
36
             state.hero.text = state.hero.url = hero.url
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
         } else {
41
         } else {
38
             state.hero.text = hero
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
     SET_GALLERY(state, idList) {
53
     SET_GALLERY(state, idList) {
42
         state.gallery = idList
54
         state.gallery = idList
43
     },
55
     },

Завантаження…
Відмінити
Зберегти