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

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

tags/0.9.0
j 4 роки тому
джерело
коміт
253feea50b

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

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

+ 13
- 21
vue-theme/src/pages/list.vue Переглянути файл

70
                       .split('/')
70
                       .split('/')
71
                       .filter(p => p)
71
                       .filter(p => p)
72
                       .pop()
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
             // Don't dispatch if there's no type
80
             // Don't dispatch if there's no type
88
             if (this.type && this.dispatchName) {
81
             if (this.type && this.dispatchName) {
89
-                console.log('Gettings posts:', this.type, this.dispatchName)
90
                 this.$store.dispatch(this.dispatchName, sort)
82
                 this.$store.dispatch(this.dispatchName, sort)
91
 
83
 
92
                 if (this.type == 'events') {
84
                 if (this.type == 'events') {
107
             if (!this['allPagesLoaded']) {
99
             if (!this['allPagesLoaded']) {
108
                 await this.$store.dispatch('getAllPages')
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
             const page = this.allPages[type]
106
             const page = this.allPages[type]
111
-            if (!page) return
112
 
107
 
113
             let json = { url: page.featured, heroType: 'image' }
108
             let json = { url: page.featured, heroType: 'image' }
114
             if (
109
             if (
125
             }
120
             }
126
             // Set the hero text to the post title or excerpt
121
             // Set the hero text to the post title or excerpt
127
             json.text = page && page.excerpt ? page.excerpt : page.title
122
             json.text = page && page.excerpt ? page.excerpt : page.title
128
-
129
             this.$store.commit('SET_HERO', json)
123
             this.$store.commit('SET_HERO', json)
130
         },
124
         },
131
         scrollTo(hashtag) {
125
         scrollTo(hashtag) {
135
         },
129
         },
136
     },
130
     },
137
     watch: {
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
             let type = convertTitleCase(this.type)
136
             let type = convertTitleCase(this.type)
141
             let sort = to.path
137
             let sort = to.path
142
                 .split('/')
138
                 .split('/')
143
                 .filter(p => p)
139
                 .filter(p => p)
144
                 .pop()
140
                 .pop()
145
-            this.checkAndSetHero(this.type)
146
 
141
 
147
-            // console.log('---', sort, type)
148
-            // console.log(`${from.path}>>>${to.path}`)
149
             if (!Object.values(sortTypes).includes(sort)) {
142
             if (!Object.values(sortTypes).includes(sort)) {
150
                 console.log('sort not found:', sort)
143
                 console.log('sort not found:', sort)
151
                 sort = null
144
                 sort = null
152
             }
145
             }
153
-            // console.log('---', sort, type)
154
 
146
 
155
             if (!this[`all${type}Loaded`] || sort) this.getPosts()
147
             if (!this[`all${type}Loaded`] || sort) this.getPosts()
156
         },
148
         },

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

165
          */
165
          */
166
         checkAndSetHero(post) {
166
         checkAndSetHero(post) {
167
             if (!post) return
167
             if (!post) return
168
-
169
             let json = { url: post.featured, heroType: 'image' }
168
             let json = { url: post.featured, heroType: 'image' }
170
             if (
169
             if (
171
                 post.hero &&
170
                 post.hero &&
181
             }
180
             }
182
             // Set the hero text to the post title
181
             // Set the hero text to the post title
183
             json.text = post.title
182
             json.text = post.title
184
-
185
             this.$store.commit('SET_HERO', json)
183
             this.$store.commit('SET_HERO', json)
186
         },
184
         },
187
 
185
 
234
     },
232
     },
235
     watch: {
233
     watch: {
236
         post(newVal, oldVal) {
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
     mounted() {
249
     mounted() {

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

24
     hero: {
24
     hero: {
25
         url: null,
25
         url: null,
26
         type: null,
26
         type: null,
27
-        text: 'sample hero text',
27
+        text: 'sample hero text', // Does this ever display?
28
         playbutton: true,
28
         playbutton: true,
29
     },
29
     },
30
     currentGallery: null,
30
     currentGallery: null,
33
 
33
 
34
 const mutations = {
34
 const mutations = {
35
     SET_HERO(state, hero) {
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
             state.hero.text = hero.text
44
             state.hero.text = hero.text
43
             state.hero.url = hero.url
45
             state.hero.url = hero.url
44
             state.hero.type = hero.heroType
46
             state.hero.type = hero.heroType
45
 
47
 
46
             state.hero.playbutton = hero.heroType === 'video' ? true : false
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
         state.loading = false
50
         state.loading = false
55
     },
51
     },

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

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

+ 4
- 3
vue-theme/src/store/modules/episode.js Переглянути файл

26
         })
26
         })
27
     },
27
     },
28
     getSingleEpisode({ commit }, id) {
28
     getSingleEpisode({ commit }, id) {
29
-        commit('CLEAR_SINGLE_EPISODE')
29
+        console.log('clearing single ep from getSingle')
30
+        commit('CLEAR_SINGLE_EPISODES')
30
         commit('EPISODES_LOADED', false)
31
         commit('EPISODES_LOADED', false)
31
         api.getSingleType('episodes', id, episode => {
32
         api.getSingleType('episodes', id, episode => {
32
             commit('STORE_FETCHED_SINGLE_EPISODE', episode)
33
             commit('STORE_FETCHED_SINGLE_EPISODE', episode)
45
     CLEAR_EPISODES(state) {
46
     CLEAR_EPISODES(state) {
46
         state.all = []
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
     EPISODES_LOADED(state, val) {
52
     EPISODES_LOADED(state, val) {
52
         state.loaded = val
53
         state.loaded = val

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

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

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

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

+ 1
- 1
vue-theme/src/store/modules/page.js Переглянути файл

4
 const state = {
4
 const state = {
5
     all: [],
5
     all: [],
6
     loaded: false,
6
     loaded: false,
7
-    singlePage: null
7
+    singlePage: null,
8
 }
8
 }
9
 
9
 
10
 // getters
10
 // getters

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

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

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