Selaa lähdekoodia

:recycle: consolidating date formatter in helper

tags/0.9.0
J 4 vuotta sitten
vanhempi
commit
5569efbe45

+ 2
- 4
vue-theme/src/components/card.vue Näytä tiedosto

@@ -22,14 +22,12 @@
22 22
 
23 23
 <script>
24 24
 import featuredImage from '@/components/featured-image'
25
+import { formatDate } from '@/utils/helpers'
25 26
 export default {
26 27
     components: { featuredImage },
27 28
     props: ['type', 'content', 'wide', 'hide-type'],
28 29
     methods: {
29
-        dateFrom(unix, includeTime) {
30
-            const d = new Date(parseInt(unix) * 1000)
31
-            return includeTime ? d.toLocaleString('en-US', { timeZone: 'UTC' }) : d.toLocaleDateString('en-US', { timeZone: 'UTC' })
32
-        }
30
+        dateFrom: (unix, includeTime) => formatDate(unix, includeTime),
33 31
     }
34 32
 }
35 33
 </script>

+ 4
- 6
vue-theme/src/components/sidebars/events.vue Näytä tiedosto

@@ -3,7 +3,8 @@
3 3
 h3.t-up {{ listType }} events
4 4
 ul.t-up
5 5
     li(v-for="post in events")
6
-        featured-image(:post="post", thumbsize="'standard'")
6
+        router-link(:to="`/event/${post.slug}`")
7
+            featured-image(:post="post", thumbsize="'standard'")
7 8
         router-link(:to="`/event/${post.slug}`")
8 9
             p.t-up {{ post.title }}
9 10
         p {{ dateFrom(post.start, true) }} &ndash; {{ dateFrom(post.end, true) }}
@@ -12,7 +13,7 @@ ul.t-up
12 13
 <script>
13 14
 import featuredImage from '@/components/featured-image'
14 15
 import { postTypeGetters } from '@/pages/mixin-post-types'
15
-import { sortTypes } from '@/utils/helpers'
16
+import { sortTypes, formatDate } from '@/utils/helpers'
16 17
 
17 18
 export default {
18 19
     mixins: [postTypeGetters],
@@ -31,10 +32,7 @@ export default {
31 32
         }
32 33
     },
33 34
     methods: {
34
-        dateFrom(unix, includeTime) {
35
-            const d = new Date(parseInt(unix) * 1000)
36
-            return includeTime ? d.toLocaleString('en-US', { timeZone: 'UTC' }) : d.toLocaleDateString('en-US', { timeZone: 'UTC' })
37
-        },
35
+        dateFrom: (unix, includeTime) => formatDate(unix, includeTime),
38 36
         async getPosts() {
39 37
             this.$store.commit('CLEAR_EVENTS')
40 38
             const upcoming = this.$store.dispatch(

+ 4
- 6
vue-theme/src/components/sidebars/exhibitions.vue Näytä tiedosto

@@ -3,7 +3,8 @@
3 3
 h3.t-up {{ listType }} exhibitions
4 4
 ul.t-up
5 5
     li(v-for="post in exhibitions")
6
-        featured-image(:post="post", thumbsize="'standard'")
6
+        router-link(:to="`/exhibition/${post.slug}`")
7
+            featured-image(:post="post", thumbsize="'standard'")
7 8
         router-link(:to="`/exhibition/${post.slug}`")
8 9
             p.t-up {{ post.title }}
9 10
         p {{ dateFrom(post.start, false) }} &ndash; {{ dateFrom(post.end, false) }}
@@ -12,7 +13,7 @@ ul.t-up
12 13
 <script>
13 14
 import featuredImage from '@/components/featured-image'
14 15
 import { postTypeGetters } from '@/pages/mixin-post-types'
15
-import { sortTypes } from '@/utils/helpers'
16
+import { sortTypes, formatDate } from '@/utils/helpers'
16 17
 
17 18
 export default {
18 19
     mixins: [postTypeGetters],
@@ -31,10 +32,7 @@ export default {
31 32
         }
32 33
     },
33 34
     methods: {
34
-        dateFrom(unix, includeTime) {
35
-            const d = new Date(parseInt(unix) * 1000)
36
-            return includeTime ? d.toLocaleString('en-US', { timeZone: 'UTC' }) : d.toLocaleDateString('en-US', { timeZone: 'UTC' })
37
-        },
35
+        dateFrom: (unix, includeTime) => formatDate(unix, includeTime),
38 36
         async getPosts() {
39 37
             this.$store.commit('CLEAR_EXHIBITIONS')
40 38
             const upcoming = this.$store.dispatch(

+ 4
- 6
vue-theme/src/pages/single.vue Näytä tiedosto

@@ -47,7 +47,7 @@ import breadcrumb from '@/components/breadcrumb'
47 47
 
48 48
 import { postTypeGetters, scrollTop, heroUtils } from './mixin-post-types'
49 49
 
50
-import { postTypes, sortTypes, convertTitleCase, dePluralize, typeFromRoute } from '@/utils/helpers'
50
+import { postTypes, sortTypes, convertTitleCase, dePluralize, typeFromRoute, formatDate } from '@/utils/helpers'
51 51
 
52 52
 const TIMEOUT = 1
53 53
 
@@ -174,10 +174,7 @@ export default {
174 174
         /**
175 175
          * Date Object from unix strings from db
176 176
          */
177
-        dateFrom(unix, includeTime) {
178
-            const d = new Date(parseInt(unix) * 1000)
179
-            return includeTime ? d.toLocaleString('en-US', { timeZone: 'UTC' }) : d.toLocaleDateString('en-US', { timeZone: 'UTC' })
180
-        },
177
+        dateFrom: (unix, includeTime) => formatDate(unix, includeTime),
181 178
 
182 179
         async loadPostData() {
183 180
             this.loading = true
@@ -200,7 +197,7 @@ export default {
200 197
 
201 198
             // Look if it exists before you try and load everything!
202 199
             if (!singlePostData) {
203
-                console.error('Could not find single post in store; Fetching everything...')
200
+                console.warn('Could not find single post in store; Fetching everything...')
204 201
                 const res = await this.$store.dispatch(
205 202
                     `getAll${convertTitleCase(this.type)}s`,
206 203
                     { sortType: null, params: null}
@@ -222,6 +219,7 @@ export default {
222 219
         },
223 220
     },
224 221
     watch: {
222
+        // This fires navigating to and away
225 223
         $route(to, from) {
226 224
             // Only load post data when navigating TO a single page
227 225
             const path = to.fullPath.split('/').filter(p => p)

+ 6
- 0
vue-theme/src/utils/helpers.js Näytä tiedosto

@@ -90,6 +90,11 @@ const ytThumbnail = (url, desiredSize) => {
90 90
     return `https://img.youtube.com/vi/${videoId[0]}/${size}.jpg`
91 91
 }
92 92
 
93
+const formatDate = (unix, includeTime) => {
94
+    const d = new Date(parseInt(unix) * 1000)
95
+    return includeTime ? d.toLocaleString('en-US', { timeZone: 'UTC' }) : d.toLocaleDateString('en-US', { timeZone: 'UTC' })
96
+}
97
+
93 98
 export {
94 99
     convertTitleCase,
95 100
     dePluralize,
@@ -97,4 +102,5 @@ export {
97 102
     sortTypes,
98 103
     postTypes,
99 104
     ytThumbnail,
105
+    formatDate
100 106
 }

Loading…
Peruuta
Tallenna