Sfoglia il codice sorgente

:bug: wrapped watchers in single vue to stop firing so often | addresses #75

tags/0.9.0
j 4 anni fa
parent
commit
253feea50b

+ 23
- 19
vue-theme/src/components/hero.vue Vedi File

@@ -1,6 +1,7 @@
1 1
 <template lang="pug">
2
-.hero.w-max.f-col(v-if="showHero && !loading")
2
+.hero.w-max.f-col(v-if="heroUrl && !loading")
3 3
     .tint.w-max
4
+    // youTube thumb with text and embedded video
4 5
     .hero--video.w-max(v-if="heroType === 'video'")
5 6
         iframe(
6 7
             v-if="isPlaying"
@@ -11,20 +12,21 @@
11 12
         .blank.f-col(v-else)
12 13
             .hero--image--overlay.w-max.f-col
13 14
                 h2.t-up.t-cntr(v-if="heroText") {{ heroText }}
14
-            img.w-max(:src="getThumbnailFromYt(showHero)" alt="hero alt image")
15
+            img.w-max(:src="getThumbnailFromYt(heroUrl)" alt="hero youTube image")
15 16
             button(v-if="showPlaybutton" @click="isPlaying = true").z-top
16
-
17
+    // Featured image with text
17 18
     .hero--image.w-max(v-else-if="heroType === 'image'")
18 19
         .hero--image--overlay.w-max.f-col
19 20
             h2.t-up.t-cntr(v-html="heroText")
20
-        img.w-max(:src="showHero" alt="hero alt image")
21
-
21
+        img.w-max(:src="heroUrl" alt="hero alt image")
22
+    // Blank just text
22 23
     .hero--image(v-else)
23 24
         .hero--image--overlay.w-max.f-col
24 25
             div(v-html="heroText")
25
-.hero.w-max.f-col(v-else-if="loading" style="justify-content: center !important;")
26
+
27
+.hero.loading.w-max.f-col(v-else-if="heroUrl && loading")
26 28
     .tint.w-max
27
-    p loading...
29
+    p loading... show hero: {{heroUrl}}
28 30
 </template>
29 31
 
30 32
 <script>
@@ -40,14 +42,14 @@ export default {
40 42
     },
41 43
     computed: {
42 44
         ...mapState({
43
-            showHero: state => state.hero.url,
45
+            heroUrl: state => state.hero.url,
44 46
             heroText: state => state.hero.text,
45 47
             loading: state => state.loading,
46 48
             heroType: state => state.hero.type,
47 49
             showPlaybutton: state => state.hero.playbutton,
48 50
         }),
49 51
         heroIdFromUrl() {
50
-            const url = this.showHero.split('/')
52
+            const url = this.heroUrl.split('/')
51 53
             return url.pop()
52 54
         },
53 55
     },
@@ -73,7 +75,7 @@ export default {
73 75
             this.$store.commit('CLEAR_HERO')
74 76
         },
75 77
         heroHeight() {
76
-            if (!this.showHero) return
78
+            if (!this.heroUrl) return
77 79
             Object.assign(this.$el.style, { height: this.heroHeight + 'px' })
78 80
         },
79 81
     },
@@ -94,6 +96,8 @@ export default {
94 96
     position: relative
95 97
     overflow: hidden
96 98
     justify-content: flex-start !important
99
+    &.loading
100
+        justify-content: center !important
97 101
     .tint
98 102
         position: absolute
99 103
         height: 100%
@@ -105,7 +109,7 @@ export default {
105 109
             /* color: $cia_white */
106 110
             position: absolute
107 111
             margin: 19% 0
108
-            h2 
112
+            h2
109 113
                 /* need better responsive solution for heading size  */
110 114
                 font-size: 3vw
111 115
                 color: $cia_white
@@ -120,23 +124,23 @@ export default {
120 124
         height: 100%
121 125
         position: relative
122 126
         z-index: 10002
123
-        
127
+
124 128
     .blank
125 129
         position: absolute
126 130
         height: inherit
127 131
         width: inherit
128 132
 
129
-        button 
133
+        button
130 134
             position: absolute
131 135
             min-height: $ms-7
132 136
             min-width: $ms-7
133 137
             background-color: rgba(170,17,0,0.4)
134 138
             border-radius: 50%
135 139
             border: 2px white solid
136
-            &:hover 
140
+            &:hover
137 141
                 border: 2px #DDD solid
138 142
                 background-color: rgba(170,170,170,0.7)
139
-            &:after 
143
+            &:after
140 144
                 content: ""
141 145
                 position: absolute
142 146
                 top: 30%
@@ -145,17 +149,17 @@ export default {
145 149
                 border-width: 1em 0 1em 1.6em
146 150
                 border-color: transparent transparent transparent white
147 151
 
148
-@media (min-width: $medium)     
149
-    button 
152
+@media (min-width: $medium)
153
+    button
150 154
         height: $ms-9
151 155
         width: $ms-9
152 156
         border-width: 3px
153
-        &:after 
157
+        &:after
154 158
             top: 18%
155 159
             left: 30%
156 160
             border-width: 1.5em 0 1.5em 2.5em
157 161
 
158
-    .hero 
162
+    .hero
159 163
         min-height: 50vh
160 164
         .embedded
161 165
             min-height: 50vh

+ 13
- 21
vue-theme/src/pages/list.vue Vedi File

@@ -70,23 +70,15 @@ export default {
70 70
                       .split('/')
71 71
                       .filter(p => p)
72 72
                       .pop()
73
-            // !: BUG
74
-            // if (Object.values(sortTypes).includes(sort)) {
75
-            //     console.log('trying to sort by:', sort)
76
-            //     console.log(
77
-            //         `sortTypes includes ${sort}:`,
78
-            //         Object.values(sortTypes).includes(sort),
79
-            //     )
80
-            // }
81 73
 
82
-            if (!Object.values(sortTypes).includes(sort)) {
83
-                console.log('Sort not found:', sort)
84
-                sort = null
85
-            }
74
+            // console.log('Gettings posts:', this.type)
75
+            // if (!Object.values(sortTypes).includes(sort)) {
76
+            //     console.log('Sort not found:', sort)
77
+            //     sort = null
78
+            // }
86 79
 
87 80
             // Don't dispatch if there's no type
88 81
             if (this.type && this.dispatchName) {
89
-                console.log('Gettings posts:', this.type, this.dispatchName)
90 82
                 this.$store.dispatch(this.dispatchName, sort)
91 83
 
92 84
                 if (this.type == 'events') {
@@ -107,8 +99,11 @@ export default {
107 99
             if (!this['allPagesLoaded']) {
108 100
                 await this.$store.dispatch('getAllPages')
109 101
             }
102
+
103
+            // We always set a hero no matter what
104
+            // Because the hero component will deal
105
+            // with how to render based on hero.url
110 106
             const page = this.allPages[type]
111
-            if (!page) return
112 107
 
113 108
             let json = { url: page.featured, heroType: 'image' }
114 109
             if (
@@ -125,7 +120,6 @@ export default {
125 120
             }
126 121
             // Set the hero text to the post title or excerpt
127 122
             json.text = page && page.excerpt ? page.excerpt : page.title
128
-
129 123
             this.$store.commit('SET_HERO', json)
130 124
         },
131 125
         scrollTo(hashtag) {
@@ -135,22 +129,20 @@ export default {
135 129
         },
136 130
     },
137 131
     watch: {
138
-        async $route(to, from) {
139
-            // console.log(this.sidebar)
132
+        posts() {
133
+            this.checkAndSetHero(this.type)
134
+        },
135
+        $route(to, from) {
140 136
             let type = convertTitleCase(this.type)
141 137
             let sort = to.path
142 138
                 .split('/')
143 139
                 .filter(p => p)
144 140
                 .pop()
145
-            this.checkAndSetHero(this.type)
146 141
 
147
-            // console.log('---', sort, type)
148
-            // console.log(`${from.path}>>>${to.path}`)
149 142
             if (!Object.values(sortTypes).includes(sort)) {
150 143
                 console.log('sort not found:', sort)
151 144
                 sort = null
152 145
             }
153
-            // console.log('---', sort, type)
154 146
 
155 147
             if (!this[`all${type}Loaded`] || sort) this.getPosts()
156 148
         },

+ 11
- 5
vue-theme/src/pages/single.vue Vedi File

@@ -165,7 +165,6 @@ export default {
165 165
          */
166 166
         checkAndSetHero(post) {
167 167
             if (!post) return
168
-
169 168
             let json = { url: post.featured, heroType: 'image' }
170 169
             if (
171 170
                 post.hero &&
@@ -181,7 +180,6 @@ export default {
181 180
             }
182 181
             // Set the hero text to the post title
183 182
             json.text = post.title
184
-
185 183
             this.$store.commit('SET_HERO', json)
186 184
         },
187 185
 
@@ -234,10 +232,18 @@ export default {
234 232
     },
235 233
     watch: {
236 234
         post(newVal, oldVal) {
237
-            this.checkAndSetHero(this.post)
235
+            // Prevent loading single post when
236
+            // navigating AWAY from the page
237
+            if (!oldVal) {
238
+                this.checkAndSetHero(newVal)
239
+            }
238 240
         },
239
-        $route(newVal, oldVal) {
240
-            this.loadPostData()
241
+        $route(to, from) {
242
+            // Only load post data when
243
+            //  navigating TO a single page
244
+            if (to.fullPath.split('/').filter(p => p).length > 1) {
245
+                this.loadPostData()
246
+            }
241 247
         },
242 248
     },
243 249
     mounted() {

+ 9
- 13
vue-theme/src/store/index.js Vedi File

@@ -24,7 +24,7 @@ const state = {
24 24
     hero: {
25 25
         url: null,
26 26
         type: null,
27
-        text: 'sample hero text',
27
+        text: 'sample hero text', // Does this ever display?
28 28
         playbutton: true,
29 29
     },
30 30
     currentGallery: null,
@@ -33,23 +33,19 @@ const state = {
33 33
 
34 34
 const mutations = {
35 35
     SET_HERO(state, hero) {
36
-        if (!hero) {
37
-            state.loading = false
38
-            return
39
-        }
40
-
41
-        if (hero.url) {
36
+        if (!hero.url) {
37
+            console.warn('No hero to set')
38
+            state.hero.url = null
39
+            state.hero.type = null
40
+            state.hero.text = ''
41
+            state.hero.playbutton = false
42
+        } else {
43
+            console.warn('Setting hero', hero)
42 44
             state.hero.text = hero.text
43 45
             state.hero.url = hero.url
44 46
             state.hero.type = hero.heroType
45 47
 
46 48
             state.hero.playbutton = hero.heroType === 'video' ? true : false
47
-        } else {
48
-            console.warn('No hero to set')
49
-            state.hero.url = hero.url
50
-            state.hero.type = hero.heroType
51
-            state.hero.text = ''
52
-            state.hero.playbutton = false
53 49
         }
54 50
         state.loading = false
55 51
     },

+ 2
- 3
vue-theme/src/store/modules/artist.js Vedi File

@@ -26,8 +26,7 @@ const actions = {
26 26
         })
27 27
     },
28 28
     getSingleArtist({ commit }, id) {
29
-        // console.log('getting single Artist...')
30
-        commit('CLEAR_SINGLE_ARTIST')
29
+        commit('CLEAR_SINGLE_ARTISTS')
31 30
         commit('ARTISTS_LOADED', false)
32 31
         api.getSingleType('artists', id, artist => {
33 32
             commit('STORE_FETCHED_SINGLE_ARTIST', artist)
@@ -46,7 +45,7 @@ const mutations = {
46 45
     CLEAR_ARTISTS(state) {
47 46
         state.all = []
48 47
     },
49
-    CLEAR_SINGLE_ARTIST(state) {
48
+    CLEAR_SINGLE_ARTISTS(state) {
50 49
         state.singleArtist = null
51 50
     },
52 51
     ARTISTS_LOADED(state, val) {

+ 4
- 3
vue-theme/src/store/modules/episode.js Vedi File

@@ -26,7 +26,8 @@ const actions = {
26 26
         })
27 27
     },
28 28
     getSingleEpisode({ commit }, id) {
29
-        commit('CLEAR_SINGLE_EPISODE')
29
+        console.log('clearing single ep from getSingle')
30
+        commit('CLEAR_SINGLE_EPISODES')
30 31
         commit('EPISODES_LOADED', false)
31 32
         api.getSingleType('episodes', id, episode => {
32 33
             commit('STORE_FETCHED_SINGLE_EPISODE', episode)
@@ -45,8 +46,8 @@ const mutations = {
45 46
     CLEAR_EPISODES(state) {
46 47
         state.all = []
47 48
     },
48
-    CLEAR_SINGLE_EPISODE(state) {
49
-        state.episode = null
49
+    CLEAR_SINGLE_EPISODES(state) {
50
+        state.singleEpisode = null
50 51
     },
51 52
     EPISODES_LOADED(state, val) {
52 53
         state.loaded = val

+ 2
- 2
vue-theme/src/store/modules/event.js Vedi File

@@ -33,7 +33,7 @@ const actions = {
33 33
         })
34 34
     },
35 35
     getSingleEvent({ commit }, id) {
36
-        commit('CLEAR_SINGLE_EVENT')
36
+        commit('CLEAR_SINGLE_EVENTS')
37 37
         commit('EVENTS_LOADED', false)
38 38
         api.getSingleType('events', id, event => {
39 39
             commit('STORE_FETCHED_SINGLE_EVENT', event)
@@ -52,7 +52,7 @@ const mutations = {
52 52
     CLEAR_EVENTS(state) {
53 53
         state.all = []
54 54
     },
55
-    CLEAR_SINGLE_EVENT(state) {
55
+    CLEAR_SINGLE_EVENTS(state) {
56 56
         state.singleEvent = null
57 57
     },
58 58
     EVENTS_LOADED(state, val) {

+ 2
- 2
vue-theme/src/store/modules/exhibition.js Vedi File

@@ -35,7 +35,7 @@ const actions = {
35 35
         })
36 36
     },
37 37
     getSingleExhibition({ commit }, id) {
38
-        commit('CLEAR_SINGLE_EXHIBITION')
38
+        commit('CLEAR_SINGLE_EXHIBITIONS')
39 39
         commit('EXHIBITIONS_LOADED', false)
40 40
         api.getSingleType('exhibitions', id, exhibition => {
41 41
             commit('STORE_FETCHED_SINGLE_EXHIBITION', exhibition)
@@ -54,7 +54,7 @@ const mutations = {
54 54
     CLEAR_EXHIBITIONS(state) {
55 55
         state.all = []
56 56
     },
57
-    CLEAR_SINGLE_EXHIBITION(state) {
57
+    CLEAR_SINGLE_EXHIBITIONS(state) {
58 58
         state.singleExhibition = null
59 59
     },
60 60
     EXHIBITIONS_LOADED(state, val) {

+ 1
- 1
vue-theme/src/store/modules/page.js Vedi File

@@ -4,7 +4,7 @@ import api from '../../utils/api'
4 4
 const state = {
5 5
     all: [],
6 6
     loaded: false,
7
-    singlePage: null
7
+    singlePage: null,
8 8
 }
9 9
 
10 10
 // getters

+ 2
- 2
vue-theme/src/store/modules/post.js Vedi File

@@ -21,7 +21,7 @@ const actions = {
21 21
         })
22 22
     },
23 23
     getSinglePost({ commit }, id) {
24
-        commit('CLEAR_SINGLE_POST')
24
+        commit('CLEAR_SINGLE_POSTS')
25 25
         commit('POSTS_LOADED', false)
26 26
         api.getSingleType('posts', id, post => {
27 27
             commit('STORE_FETCHED_SINGLE_POST', post)
@@ -40,7 +40,7 @@ const mutations = {
40 40
     CLEAR_POSTS(state) {
41 41
         state.all = []
42 42
     },
43
-    CLEAR_SINGLE_POST(state) {
43
+    CLEAR_SINGLE_POSTS(state) {
44 44
         state.singlePost = null
45 45
     },
46 46
     POSTS_LOADED(state, val) {

Loading…
Annulla
Salva