Explorar el Código

feat: working hero changes between pages

tags/0.9.0
J hace 6 años
padre
commit
c1fa4b0aad
Se han modificado 3 ficheros con 36 adiciones y 2 borrados
  1. 16
    2
      vue-theme/src/pages/list.vue
  2. 10
    0
      vue-theme/src/pages/single.vue
  3. 10
    0
      vue-theme/src/store/index.js

+ 16
- 2
vue-theme/src/pages/list.vue Ver fichero

57
             return this.$route.params.type ? this.$route.params.type : this.$route.fullPath.slice(1)
57
             return this.$route.params.type ? this.$route.params.type : this.$route.fullPath.slice(1)
58
         },
58
         },
59
         posts() {
59
         posts() {
60
-            let type = this.type.charAt(0).toUpperCase() + this.type.slice(1)
60
+            let type = this.convertTitleCase(this.type)
61
             return this[`all${type}`]
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
     mounted() {
69
     mounted() {
65
-        let type = this.type.charAt(0).toUpperCase() + this.type.slice(1)
70
+        let type = this.convertTitleCase(this.type)
66
         
71
         
67
         if(this.sortBy) {
72
         if(this.sortBy) {
68
             // TODO: Make a sorted call instead
73
             // TODO: Make a sorted call instead
70
         } else {
75
         } else {
71
             this.$store.dispatch(`getAll${type}`)
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
 </script>
89
 </script>

+ 10
- 0
vue-theme/src/pages/single.vue Ver fichero

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
     watch: {
92
     watch: {
87
             // Loads images from the DOM
94
             // Loads images from the DOM
88
             this.checkForImages(newVal)
95
             this.checkForImages(newVal)
89
             
96
             
97
+            this.checkAndSetHero(newVal)
98
+            
90
             // Gottas be on the next render tick
99
             // Gottas be on the next render tick
91
             this.$nextTick(() => {
100
             this.$nextTick(() => {
92
                 let gallery
101
                 let gallery
101
                     item.addEventListener('mouseup', event => { this.fullscreengallery = i })
110
                     item.addEventListener('mouseup', event => { this.fullscreengallery = i })
102
                 })
111
                 })
103
             })
112
             })
113
+            
104
         }
114
         }
105
     },
115
     },
106
     created() {
116
     created() {

+ 10
- 0
vue-theme/src/store/index.js Ver fichero

26
   },
26
   },
27
   view: 'list'
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
 export default new Vuex.Store({
39
 export default new Vuex.Store({
31
   actions,
40
   actions,
32
   getters,
41
   getters,
42
+  mutations,
33
   state,
43
   state,
34
   modules: {
44
   modules: {
35
       post,
45
       post,

Loading…
Cancelar
Guardar