Sfoglia il codice sorgente

feat: working hero changes between pages

tags/0.9.0
J 6 anni fa
parent
commit
c1fa4b0aad

+ 16
- 2
vue-theme/src/pages/list.vue Vedi File

@@ -57,12 +57,17 @@ export default {
57 57
             return this.$route.params.type ? this.$route.params.type : this.$route.fullPath.slice(1)
58 58
         },
59 59
         posts() {
60
-            let type = this.type.charAt(0).toUpperCase() + this.type.slice(1)
60
+            let type = this.convertTitleCase(this.type)
61 61
             return this[`all${type}`]
62 62
         },
63 63
     },
64
+    methods: {
65
+        convertTitleCase(type) {
66
+            return type.charAt(0).toUpperCase() + type.slice(1)
67
+        }
68
+    },
64 69
     mounted() {
65
-        let type = this.type.charAt(0).toUpperCase() + this.type.slice(1)
70
+        let type = this.convertTitleCase(this.type)
66 71
         
67 72
         if(this.sortBy) {
68 73
             // TODO: Make a sorted call instead
@@ -70,6 +75,15 @@ export default {
70 75
         } else {
71 76
             this.$store.dispatch(`getAll${type}`)
72 77
         }
78
+        this.$store.commit('SET_HERO', type)
79
+    },
80
+    watch: {
81
+        $route(to, from){
82
+            let type = this.convertTitleCase(to.path.slice(1))
83
+            if(this.$store.state.hero.url !== type) {
84
+                this.$store.commit('SET_HERO', type)
85
+            }
86
+        }
73 87
     }
74 88
 }
75 89
 </script>

+ 10
- 0
vue-theme/src/pages/single.vue Vedi File

@@ -80,6 +80,13 @@ export default {
80 80
                     )
81 81
                 }
82 82
             })
83
+        },
84
+        checkAndSetHero(posts) {
85
+            const post = posts[this.$route.params.slug]
86
+            if(post && post.hero){
87
+                const json = JSON.parse(post.hero)
88
+                this.$store.commit('SET_HERO', json)
89
+            }
83 90
         }
84 91
     },
85 92
     watch: {
@@ -87,6 +94,8 @@ export default {
87 94
             // Loads images from the DOM
88 95
             this.checkForImages(newVal)
89 96
             
97
+            this.checkAndSetHero(newVal)
98
+            
90 99
             // Gottas be on the next render tick
91 100
             this.$nextTick(() => {
92 101
                 let gallery
@@ -101,6 +110,7 @@ export default {
101 110
                     item.addEventListener('mouseup', event => { this.fullscreengallery = i })
102 111
                 })
103 112
             })
113
+            
104 114
         }
105 115
     },
106 116
     created() {

+ 10
- 0
vue-theme/src/store/index.js Vedi File

@@ -26,10 +26,20 @@ const state = {
26 26
   },
27 27
   view: 'list'
28 28
 }
29
+const mutations = {
30
+  SET_HERO(state, hero) {
31
+    if (hero.url) {
32
+      state.hero.text = state.hero.url = hero.url
33
+    } else {
34
+      state.hero.text = hero
35
+    }
36
+  },
37
+}
29 38
 
30 39
 export default new Vuex.Store({
31 40
   actions,
32 41
   getters,
42
+  mutations,
33 43
   state,
34 44
   modules: {
35 45
       post,

Loading…
Annulla
Salva