瀏覽代碼

:sparkles: address #56 | adding check for route #

tags/0.9.0
j 4 年之前
父節點
當前提交
f437aa3783
共有 2 個文件被更改,包括 150 次插入175 次删除
  1. 53
    59
      vue-theme/src/pages/list.vue
  2. 97
    116
      vue-theme/src/pages/single.vue

+ 53
- 59
vue-theme/src/pages/list.vue 查看文件

@@ -31,16 +31,19 @@ import { postTypeGetters, scrollTop } from './mixin-post-types'
31 31
 
32 32
 import { convertTitleCase, typeFromRoute, sortTypes } from '@/utils/helpers'
33 33
 
34
+const TIMEOUT = 1
35
+
34 36
 export default {
35 37
     components: { sidebar, featuredImage, card },
36 38
     props: {
37 39
         sidebar: { type: Boolean },
38 40
         grid: { type: Boolean },
39
-        sortBy: { type: String }
41
+        sortBy: { type: String },
40 42
     },
41 43
     mixins: [postTypeGetters, scrollTop],
42 44
     computed: {
43
-        type() { // Checks for type and fixes Episodes route edge case 
45
+        type() {
46
+            // Checks for type and fixes Episodes route edge case
44 47
             return typeFromRoute(this.$route)
45 48
         },
46 49
         dispatchName() {
@@ -49,45 +52,54 @@ export default {
49 52
         },
50 53
         loaded() {
51 54
             let type = convertTitleCase(this.type)
52
-            if(!type) return
55
+            if (!type) return
53 56
             return this[`all${type}Loaded`]
54 57
         },
55 58
         posts() {
56 59
             let type = convertTitleCase(this.type)
57
-            if(!type) return
60
+            if (!type) return
58 61
             return this[`all${type}`]
59 62
         },
60 63
     },
61 64
     methods: {
62 65
         getPosts() {
63 66
             // Sorting
64
-            let sort = this.sortBy ? this.sortBy : this.$route.path.split('/').pop()
67
+            let sort = this.sortBy
68
+                ? this.sortBy
69
+                : this.$route.path.split('/').pop()
65 70
             // !: BUG
66 71
             // if(this.type !== sort || !Object.values(sortTypes).includes(sort)) sort = null
67
-            if(Object.values(sortTypes).includes(sort)) {
72
+            if (Object.values(sortTypes).includes(sort)) {
68 73
                 console.log('trying to sort by:', sort)
69
-                console.log(`sortTypes includes ${sort}:`, Object.values(sortTypes).includes(sort))
74
+                console.log(
75
+                    `sortTypes includes ${sort}:`,
76
+                    Object.values(sortTypes).includes(sort),
77
+                )
70 78
             }
71
-            
79
+
72 80
             // Don't dispatch if there's no type
73
-            if(this.type && this.dispatchName) {
81
+            if (this.type && this.dispatchName) {
74 82
                 this.$store.dispatch(this.dispatchName, sort)
75 83
             }
76 84
         },
77 85
         async checkAndSetHero(type) {
78
-            if(!this['allPagesLoaded']) {
86
+            if (!this['allPagesLoaded']) {
79 87
                 await this.$store.dispatch('getAllPages')
80 88
             }
81 89
             const page = this.allPages[type]
82
-            if(!page) return
83
-            
90
+            if (!page) return
91
+
84 92
             let json = { url: page.featured, heroType: 'image' }
85
-            if(page.hero && JSON.parse(page.hero) && JSON.parse(page.hero).url) {
93
+            if (
94
+                page.hero &&
95
+                JSON.parse(page.hero) &&
96
+                JSON.parse(page.hero).url
97
+            ) {
86 98
                 json = JSON.parse(page.hero)
87 99
                 json.heroType = 'video'
88 100
             }
89 101
             // No featured or youTube
90
-            if(!json.url) {
102
+            if (!json.url) {
91 103
                 json.heroType = null
92 104
             }
93 105
             // Set the hero text to the post title or excerpt
@@ -95,66 +107,48 @@ export default {
95 107
 
96 108
             this.$store.commit('SET_HERO', json)
97 109
         },
110
+        scrollTo(hashtag) {
111
+            setTimeout(() => {
112
+                location.href = hashtag
113
+            }, TIMEOUT)
114
+        },
98 115
     },
99 116
     watch: {
100
-        async $route(to, from){
117
+        async $route(to, from) {
101 118
             // console.log(this.sidebar)
102 119
             let type = convertTitleCase(this.type)
103 120
             let sort = this.sortBy ? this.sortBy : to.path.split('/').pop()
104 121
             this.checkAndSetHero(this.type)
105 122
             // console.log('---')
106 123
             // console.log(sort)
107
-            if(!this[`all${type}Loaded`] || sort) this.getPosts()
124
+            if (!this[`all${type}Loaded`] || sort) this.getPosts()
125
+        },
126
+    },
127
+    mounted() {
128
+        if (this.$route.hash) {
129
+            setTimeout(() => this.scrollTo(this.$route.hash), TIMEOUT)
108 130
         }
109 131
     },
110 132
     created() {
111 133
         let type = convertTitleCase(this.type)
112 134
         console.log(`${type} already loaded?:`, this[`all${type}Loaded`])
113
-        
135
+
114 136
         this.checkAndSetHero(this.type)
115
-        
116
-        if(!this[`all${type}Loaded`]) this.getPosts()
117
-    }
137
+
138
+        if (!this[`all${type}Loaded`]) this.getPosts()
139
+    },
118 140
 }
119 141
 </script>
120 142
 
121 143
 <style lang="postcss">
122
-@import '../sss/variables.sss'
123
-@import '../sss/theme.sss'
124
-.page--list
125
-    /* background-color: white */
126
-    article
127
-        > header
128
-            /* padding: 1em 0 1em 0 */
129
-            padding: 1em
130
-            > h1
131
-                margin: 0
132
-            > .content
133
-                padding: 0
134
-                width: 100%
135
-        /* posts not grid list */
136
-        ul
137
-            img
138
-                max-width: 50%
139
-
140
-        .is-grid
141
-            display: flex
142
-            flex-direction: row
143
-            flex-wrap: wrap
144
-            justify-content: space-between
145
-            /* extra padding required? */
146
-            /* padding: $ms-0 */
147
-            /* background-color: white */
148
-            section
149
-                width: 32.5%
150
-                /* 4 column grid see how dense this becomes */
151
-                /* width: 24% */
152
-            ul
153
-                flex-wrap: wrap
154
-                list-style: none
155
-                img
156
-                    max-width: 100%
157
-@media (min-width: $medium)
158
-    .page--list.f-col
159
-        flex-direction: row
160
-</style>
144
+@import '../sss/variables.sss' @import '../sss/theme.sss' .page--list
145
+    /* background-color: white */ article > header /* padding: 1em 0 1em 0 */
146
+    padding: 1em > h1 margin: 0 > .content padding: 0 width: 100%
147
+    /* posts not grid list */ ul img max-width: 50% .is-grid display: flex
148
+    flex-direction: row flex-wrap: wrap justify-content: space-between
149
+    /* extra padding required? */ /* padding: $ms-0 */
150
+    /* background-color: white */ section width: 32.5%
151
+    /* 4 column grid see how dense this becomes */ /* width: 24% */ ul flex-wrap:
152
+    wrap list-style: none img max-width: 100% @media (min-width: $medium)
153
+    .page--list.f-col flex-direction: row;
154
+</style>

+ 97
- 116
vue-theme/src/pages/single.vue 查看文件

@@ -48,43 +48,47 @@ import breadcrumb from '@/components/breadcrumb'
48 48
 import { postTypeGetters, scrollTop } from './mixin-post-types'
49 49
 
50 50
 import { convertTitleCase, dePluralize, typeFromRoute } from '@/utils/helpers'
51
- 
51
+
52
+const TIMEOUT = 1
53
+
52 54
 export default {
53 55
     components: { sidebar, gallery, credits, card, breadcrumb },
54 56
     props: {
55 57
         sidebar: { type: Boolean },
56
-        id: { type: Number }
58
+        id: { type: Number },
57 59
     },
58 60
     mixins: [postTypeGetters, scrollTop],
59 61
     data() {
60 62
         return {
61 63
             // Gallery control
62 64
             activeGalleryIndex: -1,
63
-            activeImageID: -1
65
+            activeImageID: -1,
64 66
         }
65 67
     },
66 68
     computed: {
67
-        type() { // Checks for type and fixes Episodes route edge case
69
+        type() {
70
+            // Checks for type and fixes Episodes route edge case
68 71
             return typeFromRoute(this.$route)
69 72
         },
70 73
         /**
71 74
          * We get the actual post data using the slug
72 75
          */
73 76
         post() {
74
-            if(!this[this.type]) return
77
+            if (!this[this.type]) return
75 78
 
76 79
             const type = dePluralize(this.type)
77 80
 
78 81
             // State not a getter!
79
-            const singleOfTypeFromState = this[this.type][`single${convertTitleCase(type)}`]
82
+            const singleOfTypeFromState =
83
+                this[this.type][`single${convertTitleCase(type)}`]
80 84
 
81
-            if(!singleOfTypeFromState) return
85
+            if (!singleOfTypeFromState) return
82 86
 
83 87
             return singleOfTypeFromState
84 88
         },
85 89
 
86 90
         idsForGallery() {
87
-            if(!this.post || this.activeGalleryIndex < 0) return []
91
+            if (!this.post || this.activeGalleryIndex < 0) return []
88 92
             return this.post.galleries[this.activeGalleryIndex].ids
89 93
         },
90 94
         /**
@@ -94,7 +98,7 @@ export default {
94 98
          * image size and url information returned by post.attached
95 99
          */
96 100
         imagesInGallery() {
97
-            if(!this.activeGalleryIndex < 0) return {}
101
+            if (!this.activeGalleryIndex < 0) return {}
98 102
 
99 103
             return this.idsForGallery.reduce((imageMap, id) => {
100 104
                 imageMap[id] = this.post.attached[parseInt(id)]
@@ -102,15 +106,23 @@ export default {
102 106
             }, {})
103 107
         },
104 108
         activeImageIndex() {
105
-            return Object.keys(this.imagesInGallery).indexOf(this.activeImageID.toString())
109
+            return Object.keys(this.imagesInGallery).indexOf(
110
+                this.activeImageID.toString(),
111
+            )
106 112
         },
107 113
         p2pPostsByType() {
108
-            return this.post ? Object.values(this.post.relatedto).reduce((byType, relatedPost) => {
109
-                if(!byType[relatedPost.type]) byType[relatedPost.type] = []
110
-                byType[relatedPost.type].push(relatedPost)
111
-                return byType
112
-            }, {}) : {}
113
-        }
114
+            return this.post
115
+                ? Object.values(this.post.relatedto).reduce(
116
+                      (byType, relatedPost) => {
117
+                          if (!byType[relatedPost.type])
118
+                              byType[relatedPost.type] = []
119
+                          byType[relatedPost.type].push(relatedPost)
120
+                          return byType
121
+                      },
122
+                      {},
123
+                  )
124
+                : {}
125
+        },
114 126
     },
115 127
     methods: {
116 128
         /**
@@ -121,16 +133,26 @@ export default {
121 133
          * @param {string} imageInfo
122 134
          */
123 135
         openGallery(imageInfo) {
124
-            const byIndex = this.post.galleries.reduce((byIndex, gallery, index) => {
125
-                byIndex[index] = gallery.ids
126
-                return byIndex
127
-            }, {})
136
+            const byIndex = this.post.galleries.reduce(
137
+                (byIndex, gallery, index) => {
138
+                    byIndex[index] = gallery.ids
139
+                    return byIndex
140
+                },
141
+                {},
142
+            )
128 143
             let matchingIndex = 0
129 144
             Object.keys(byIndex).forEach(galleryIndex => {
130
-                if(byIndex[galleryIndex].includes(parseInt(imageInfo.dataset.id))) matchingIndex = galleryIndex
145
+                if (
146
+                    byIndex[galleryIndex].includes(
147
+                        parseInt(imageInfo.dataset.id),
148
+                    )
149
+                )
150
+                    matchingIndex = galleryIndex
131 151
             })
132 152
             this.activeGalleryIndex = matchingIndex
133
-            this.activeImageID = imageInfo.dataset.id ? parseInt(imageInfo.dataset.id) : parseInt(imageInfo.className.split('-').pop())
153
+            this.activeImageID = imageInfo.dataset.id
154
+                ? parseInt(imageInfo.dataset.id)
155
+                : parseInt(imageInfo.className.split('-').pop())
134 156
         },
135 157
         closeGallery() {
136 158
             this.activeGalleryIndex = this.activeImageID = -1
@@ -142,28 +164,32 @@ export default {
142 164
          * @param {object} posts
143 165
          */
144 166
         checkAndSetHero(post) {
145
-            if(!post) return
167
+            if (!post) return
146 168
 
147 169
             let json = { url: post.featured, heroType: 'image' }
148
-            if(post.hero && JSON.parse(post.hero) && JSON.parse(post.hero).url) {
170
+            if (
171
+                post.hero &&
172
+                JSON.parse(post.hero) &&
173
+                JSON.parse(post.hero).url
174
+            ) {
149 175
                 json = JSON.parse(post.hero)
150 176
                 json.heroType = 'video'
151 177
             }
152 178
             // No featured or youTube
153
-            if(!json.url) {
179
+            if (!json.url) {
154 180
                 json.heroType = null
155 181
             }
156 182
             // Set the hero text to the post title
157 183
             json.text = post.title
158
-            
184
+
159 185
             this.$store.commit('SET_HERO', json)
160 186
         },
161
-        
187
+
162 188
         /**
163 189
          * Date Object from unix strings from db
164 190
          */
165 191
         dateFrom(unix) {
166
-            return new Date( parseInt(unix) * 1000 )
192
+            return new Date(parseInt(unix) * 1000)
167 193
         },
168 194
 
169 195
         async loadPostData() {
@@ -173,27 +199,38 @@ export default {
173 199
              * !: posts watcher fires when this finishes
174 200
              */
175 201
             let type = convertTitleCase(this.type)
176
-            
177
-            if(!this.$store.state[this.type]) return 
202
+
203
+            if (!this.$store.state[this.type]) return
178 204
 
179 205
             let allPostsOfType = this.$store.state[this.type].all
180 206
 
181 207
             /**
182 208
              * Load posts if they're not already in state
183 209
              */
184
-            if(!this[`all${type}Loaded`] && allPostsOfType.length < 1) {
210
+            if (!this[`all${type}Loaded`] && allPostsOfType.length < 1) {
185 211
                 const res = await this.$store.dispatch(`getAll${type}`)
186 212
                 allPostsOfType = res
187 213
                 // console.log(`reloaded ${type}...`)
188 214
             }
189 215
 
190
-            if(Object.values(allPostsOfType).length < 1) return
191
-            const singlePostData = Object.values(allPostsOfType).filter(post => post.slug == this.$route.params.slug)[0]
216
+            if (Object.values(allPostsOfType).length < 1) return
217
+            const singlePostData = Object.values(allPostsOfType).filter(
218
+                post => post.slug == this.$route.params.slug,
219
+            )[0]
192 220
 
193
-            if(!singlePostData) return
221
+            if (!singlePostData) return
194 222
 
195
-            await this.$store.dispatch(`getSingle${dePluralize(type)}`, singlePostData.id)
196
-        }
223
+            await this.$store.dispatch(
224
+                `getSingle${dePluralize(type)}`,
225
+                singlePostData.id,
226
+            )
227
+        },
228
+
229
+        scrollTo(hashtag) {
230
+            setTimeout(() => {
231
+                location.href = hashtag
232
+            }, TIMEOUT)
233
+        },
197 234
     },
198 235
     watch: {
199 236
         post(newVal, oldVal) {
@@ -201,92 +238,36 @@ export default {
201 238
         },
202 239
         $route(newVal, oldVal) {
203 240
             this.loadPostData()
241
+        },
242
+    },
243
+    mounted() {
244
+        if (this.$route.hash) {
245
+            setTimeout(() => this.scrollTo(this.$route.hash), TIMEOUT)
204 246
         }
205 247
     },
206 248
     async created() {
207 249
         await this.loadPostData()
208 250
         this.checkAndSetHero(this.post)
209
-    }
251
+    },
210 252
 }
211 253
 </script>
212 254
 
213 255
 <style lang="postcss">
214
-@import '../sss/variables.sss'
215
-@import '../sss/theme.sss'
216
-.page--single
217
-    /* background-color: $cia_white2 */
218
-    article
219
-        background-color: white
220
-        padding: $ms-0
221
-        h1
222
-            color: $cia_black
223
-            /* font-weight: 800 */
224
-            /* padding: $ms--3 0 */
225
-        > ul
226
-            /* grid-gap: $ms-0 */
227
-            list-style: none
228
-            /* change to a 1/3 width of the article*/
229
-            img.feature
230
-                width: 20em 
231
-            li
232
-        /* iframe container 16:9 */
233
-        .iframe-container 
234
-            position: relative
235
-            width: 100% 
236
-            padding-bottom: 56.25% 
237
-
238
-        /* iframe container portrait */
239
-        .iframe-container-v
240
-            position: relative
241
-            width: 100%
242
-            height: 100%
243
-            padding-bottom: 125%
244
-            
245
-        iframe 
246
-            position: absolute 
247
-            top: 0px 
248
-            left: 0px 
249
-            width: 100% 
250
-            height: 100%
251
-        
252
-        .wp-block-embed .is-type-video
253
-            position: relative
254
-            width: 100% 
255
-            padding-bottom: 56.25% 
256
-
257
-        * hr
258
-            border: $ms--3
259
-            margin: $ms-2 auto
260
-            outline-style: auto
261
-
262
-            &.is-style-default
263
-                height: 1px
264
-                width: 15vw
265
-
266
-            &.is-style-wide
267
-                height: 1px
268
-                width: 50vw
269
-        
270
-            &.is-style-dots
271
-                outline-style: none
272
-                font-weight: bolder
273
-
274
-        breadcrumb
275
-            h5
276
-                /* color: yellow */
277
-                color: $cia_red
278
-                /* font-weight: 400 */
279
-                /* padding: $ms--6 0 */
280
-        
281
-        //- end of article icon
282
-        footer
283
-            padding: $ms-6 0
284
-            img
285
-                height: $ms-3
286
-                width: $ms-3
287
-
288
-        
289
-@media (min-width: $medium)
290
-    .page--single.f-col
291
-        flex-direction: row
292
-</style>
256
+@import '../sss/variables.sss' @import '../sss/theme.sss' .page--single
257
+    /* background-color: $cia_white2 */ article background-color: white padding:
258
+    $ms-0 h1 color: $cia_black /* font-weight: 800 */ /* padding: $ms--3 0 */ >
259
+    ul /* grid-gap: $ms-0 */ list-style: none
260
+    /* change to a 1/3 width of the article*/ img.feature width: 20em li
261
+    /* iframe container 16:9 */ .iframe-container position: relative width: 100%
262
+    padding-bottom: 56.25% /* iframe container portrait */ .iframe-container-v
263
+    position: relative width: 100% height: 100% padding-bottom: 125% iframe
264
+    position: absolute top: 0px left: 0px width: 100% height: 100%
265
+    .wp-block-embed .is-type-video position: relative width: 100% padding-bottom:
266
+    56.25% * hr border: $ms--3 margin: $ms-2 auto outline-style: auto
267
+    &.is-style-default height: 1px width: 15vw &.is-style-wide height: 1px width:
268
+    50vw &.is-style-dots outline-style: none font-weight: bolder breadcrumb h5
269
+    /* color: yellow */ color: $cia_red /* font-weight: 400 */
270
+    /* padding: $ms--6 0 */ //- end of article icon
271
+    footer padding: $ms-6 0 img height: $ms-3 width: $ms-3 @media
272
+    (min-width: $medium) .page--single.f-col flex-direction: row;
273
+</style>

Loading…
取消
儲存