Bladeren bron

:sparkles: adding auto-scroll mixing on page mount | cleaning up sort type definitions | altering route matcher to use fullPath

tags/0.9.0
J 5 jaren geleden
bovenliggende
commit
02858750bb

+ 7
- 7
vue-theme/src/components/sidebars/sidebar.vue Bestand weergeven

@@ -13,7 +13,7 @@ aside.sidebar
13 13
 </template>
14 14
 
15 15
 <script>
16
-import { mapGetters } from 'vuex'
16
+import { sortTypes } from '@/utils/helpers'
17 17
 
18 18
 export default {
19 19
     props: {
@@ -27,11 +27,11 @@ export default {
27 27
     data() {
28 28
         return {
29 29
             sortTypes: {
30
-                'most recent': '',
31
-                'alphabetized': 'by-alpha',
32
-                'by material': 'by-material',
33
-                'by artist': 'by-artist',
34
-                'by episode': 'by-episode',
30
+                'most recent': `${sortTypes.recent}`,
31
+                'alphabetized': `${sortTypes.alpha}`,
32
+                'by material': `${sortTypes.material}`,
33
+                'by artist': `${sortTypes.artist}`,
34
+                'by episode': `${sortTypes.episode}`,
35 35
             }
36 36
         }
37 37
     },
@@ -69,7 +69,7 @@ export default {
69 69
 <style lang="postcss">
70 70
 aside.sidebar
71 71
     position: sticky
72
-    top: 124px
72
+    top: 65px
73 73
     ul
74 74
         list-style: none
75 75
 </style>

+ 3
- 3
vue-theme/src/pages/index.vue Bestand weergeven

@@ -32,14 +32,14 @@
32 32
 </template>
33 33
 
34 34
 <script>
35
-import { postTypeGetters } from './mixin-post-types'
35
+import { postTypeGetters, scrollTop } from './mixin-post-types'
36 36
 
37 37
 import { convertTitleCase, postTypes } from '@/utils/helpers'
38 38
 
39 39
 export default {
40
-    mixins: [postTypeGetters],
40
+    mixins: [postTypeGetters, scrollTop],
41 41
     created() {
42
-        console.log(wp)
42
+        // console.log(wp)
43 43
 
44 44
         postTypes.forEach(type => {
45 45
             const capitalizedType = convertTitleCase(type)

+ 10
- 7
vue-theme/src/pages/list.vue Bestand weergeven

@@ -9,6 +9,7 @@
9 9
         .posts(:class="{ 'is-grid': grid }")
10 10
             section(v-for="post in posts" :key="post.slug").shadow.post
11 11
                 router-link(:to="`/${type}/${post.slug}`")
12
+                    p {{ post.featured }}
12 13
                     h4 {{ post.title }} 
13 14
                     p(style="font-size: 9px;") {{ post.date }}
14 15
 
@@ -26,7 +27,7 @@
26 27
 
27 28
 <script>
28 29
 import sidebar from '@/components/sidebars/sidebar'
29
-import { postTypeGetters } from './mixin-post-types'
30
+import { postTypeGetters, scrollTop } from './mixin-post-types'
30 31
 
31 32
 import { convertTitleCase, typeFromRoute, sortTypes } from '@/utils/helpers'
32 33
 
@@ -37,7 +38,7 @@ export default {
37 38
         grid: { type: Boolean },
38 39
         sortBy: { type: String }
39 40
     },
40
-    mixins: [postTypeGetters],
41
+    mixins: [postTypeGetters, scrollTop],
41 42
     computed: {
42 43
         type() { // Checks for type and fixes Episodes route edge case 
43 44
             return typeFromRoute(this.$route)
@@ -54,7 +55,7 @@ export default {
54 55
              * We override the API to sort by date
55 56
              * because items are returned by ID so
56 57
              * we need to resort it by date
57
-             */ 
58
+             */
58 59
             let unsortedOfType = Object.values(this[`all${type}`])
59 60
             let sortedByRecent = unsortedOfType.sort((postA, postB) => new Date(postB.date) - new Date(postA.date))
60 61
             
@@ -69,11 +70,13 @@ export default {
69 70
     methods: {
70 71
         setHeroAndGetPosts() {
71 72
             let type = convertTitleCase(this.type)
72
-
73
-            let sort = this.sortBy ? this.sortBy : this.$route.path.split('/').pop()
74 73
             
75
-            console.log('trying to sort by:', sort)
76
-            console.log('includes:', Object.values(sortTypes).includes(sort))
74
+            // Sorting
75
+            let sort = this.sortBy ? this.sortBy : this.$route.path.split('/').pop()
76
+            if(Object.values(sortTypes).includes(sort)) {
77
+                console.log('trying to sort by:', sort)
78
+                console.log(`sortTypes includes ${sort}:`, Object.values(sortTypes).includes(sort))
79
+            }
77 80
 
78 81
             // Is this a sort type?
79 82
             if(this.type !== sort || !Object.values(sortTypes).includes(sort)) sort = null

+ 6
- 1
vue-theme/src/pages/mixin-post-types.js Bestand weergeven

@@ -25,5 +25,10 @@ const postTypeGetters = {
25 25
         ...mapState(stateHelper)
26 26
     }
27 27
 }
28
+const scrollTop = {
29
+    mounted() {
30
+        window.scrollTo(0, 0)
31
+    }
32
+}
28 33
 
29
-export { postTypeGetters }
34
+export { postTypeGetters, scrollTop }

+ 3
- 3
vue-theme/src/pages/single.vue Bestand weergeven

@@ -21,7 +21,7 @@
21 21
         //- related artists section example layout
22 22
         section
23 23
             h2.t-up featured in this episode
24
-            ul.f-row.f-start
24
+            ul.f-col.f-start
25 25
                 li
26 26
                     img(src="https://i1.wp.com/www.craftinamerica.org/wp-content/uploads/2020/09/20200210_133120-e1599254267307.jpg")
27 27
                     h2.t-up Julie Schafler Dale
@@ -49,7 +49,7 @@ import block from '@/components/content-block/block'
49 49
 // import artists from '@/components/artist'
50 50
 import credits from '@/components/credits'
51 51
 
52
-import { postTypeGetters } from './mixin-post-types'
52
+import { postTypeGetters, scrollTop } from './mixin-post-types'
53 53
 
54 54
 import { convertTitleCase, dePluralize, typeFromRoute } from '@/utils/helpers'
55 55
 
@@ -59,7 +59,7 @@ export default {
59 59
         sidebar: { type: Boolean },
60 60
         id: { type: Number }
61 61
     },
62
-    mixins: [postTypeGetters],
62
+    mixins: [postTypeGetters, scrollTop],
63 63
     data() {
64 64
         return {
65 65
             // Gallery control

+ 20
- 3
vue-theme/src/router/routes.js Bestand weergeven

@@ -2,6 +2,8 @@ import indexPage from '@/pages/index.vue'
2 2
 import listPage from '@/pages/list.vue'
3 3
 import singlePage from '@/pages/single.vue'
4 4
 
5
+import { sortTypes } from '@/utils/helpers'
6
+
5 7
 export default [
6 8
     // Home Page
7 9
     { path: '/', component: indexPage },
@@ -11,11 +13,26 @@ export default [
11 13
         component: listPage,
12 14
         props: { sidebar: false, grid: true }
13 15
     },
16
+    { 
17
+        path: '/artists',
18
+        component: listPage,
19
+        props: { sidebar: true, grid: true }
20
+    },
14 21
     { path: '/:type', component: listPage, props: { sidebar: true } },
15 22
     // Sorted List Pages 
16
-    { path: '/:type/by-alpha', component: listPage, props: { sidebar: true, sortBy: 'by-alpha' } },
17
-    { path: '/:type/recent', component: listPage, props: { sidebar: true, sortBy: 'recent' } },
18
-    { path: '/:type/by-material', component: listPage, props: { sidebar: true, sortBy: 'by-material' } },
23
+    { 
24
+        path: `/artists/${sortTypes.alpha}`,
25
+        component: listPage,
26
+        props: { sidebar: true, grid: true, sortBy: `${sortTypes.alpha}` }
27
+    },
28
+    { 
29
+        path: `/artists/${sortTypes.recent}`,
30
+        component: listPage,
31
+        props: { sidebar: true, grid: true, sortBy: `${sortTypes.material}` }
32
+    },
33
+    { path: `/:type/${sortTypes.alpha}`, component: listPage, props: { sidebar: true, sortBy: `${sortTypes.alpha}` } },
34
+    { path: `/:type/${sortTypes.recent}`, component: listPage, props: { sidebar: true, sortBy: `${sortTypes.recent}` } },
35
+    { path: `/:type/${sortTypes.material}`, component: listPage, props: { sidebar: true, sortBy: `${sortTypes.material}` } },
19 36
     { path: '/:type/by-episode', component: listPage, props: { sidebar: true, sortBy: 'by-episode' } },
20 37
     { path: '/:type/by-artist', component: listPage, props: { sidebar: true, sortBy: 'by-artist' } },
21 38
     // Single Pages

+ 25
- 6
vue-theme/src/utils/helpers.js Bestand weergeven

@@ -7,15 +7,12 @@ const dePluralize = type => {
7 7
     return type[type.length - 1] === 's' ? type.slice(0, -1) : type
8 8
 }
9 9
 
10
-const typeFromRoute = (route) => {
11
-    const type = route.params.type ? route.params.type : route.path.slice(1)
12
-    return type
13
-}
14
-
15 10
 const sortTypes = {
16 11
     alpha: 'by-alpha',
17 12
     recent: 'by-recent',
18 13
     material: 'by-material',
14
+    artist: 'by-artist',
15
+    episode: 'by-episode',
19 16
 }
20 17
 
21 18
 /**
@@ -23,7 +20,7 @@ const sortTypes = {
23 20
  * This makes ALL post type modules available for the
24 21
  * list and single components to request data
25 22
  */
26
- const postTypes = [
23
+const postTypes = [
27 24
     'episodes',
28 25
     'artists',
29 26
     'exhibitions',
@@ -32,4 +29,26 @@ const sortTypes = {
32 29
     'pages',
33 30
 ]
34 31
 
32
+/**
33
+ * Type assigned from Route :type
34
+ * In case of failure, tries to derive type
35
+ * matching pieces to postTypes array
36
+ */
37
+const typeFromRoute = route => {
38
+    let type = route.params.type ? route.params.type : route.fullPath.split('/')
39
+
40
+    if(!route.params.type) {
41
+        // Remove blank path sections and match to postTypes array
42
+        type = type
43
+            .filter(pathSection => pathSection != '')
44
+            .filter(pathSection => postTypes.includes(pathSection))
45
+        
46
+        // Only take the first match
47
+        type = type[0]
48
+        console.log(`type derived from route.path: ${type}`)
49
+    }
50
+    
51
+    return type
52
+}
53
+
35 54
 export { convertTitleCase, dePluralize, typeFromRoute, sortTypes, postTypes }

Laden…
Annuleren
Opslaan