Преглед изворни кода

: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 година
родитељ
комит
02858750bb

+ 7
- 7
vue-theme/src/components/sidebars/sidebar.vue Прегледај датотеку

13
 </template>
13
 </template>
14
 
14
 
15
 <script>
15
 <script>
16
-import { mapGetters } from 'vuex'
16
+import { sortTypes } from '@/utils/helpers'
17
 
17
 
18
 export default {
18
 export default {
19
     props: {
19
     props: {
27
     data() {
27
     data() {
28
         return {
28
         return {
29
             sortTypes: {
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
 <style lang="postcss">
69
 <style lang="postcss">
70
 aside.sidebar
70
 aside.sidebar
71
     position: sticky
71
     position: sticky
72
-    top: 124px
72
+    top: 65px
73
     ul
73
     ul
74
         list-style: none
74
         list-style: none
75
 </style>
75
 </style>

+ 3
- 3
vue-theme/src/pages/index.vue Прегледај датотеку

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

+ 10
- 7
vue-theme/src/pages/list.vue Прегледај датотеку

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

+ 6
- 1
vue-theme/src/pages/mixin-post-types.js Прегледај датотеку

25
         ...mapState(stateHelper)
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 Прегледај датотеку

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

+ 20
- 3
vue-theme/src/router/routes.js Прегледај датотеку

2
 import listPage from '@/pages/list.vue'
2
 import listPage from '@/pages/list.vue'
3
 import singlePage from '@/pages/single.vue'
3
 import singlePage from '@/pages/single.vue'
4
 
4
 
5
+import { sortTypes } from '@/utils/helpers'
6
+
5
 export default [
7
 export default [
6
     // Home Page
8
     // Home Page
7
     { path: '/', component: indexPage },
9
     { path: '/', component: indexPage },
11
         component: listPage,
13
         component: listPage,
12
         props: { sidebar: false, grid: true }
14
         props: { sidebar: false, grid: true }
13
     },
15
     },
16
+    { 
17
+        path: '/artists',
18
+        component: listPage,
19
+        props: { sidebar: true, grid: true }
20
+    },
14
     { path: '/:type', component: listPage, props: { sidebar: true } },
21
     { path: '/:type', component: listPage, props: { sidebar: true } },
15
     // Sorted List Pages 
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
     { path: '/:type/by-episode', component: listPage, props: { sidebar: true, sortBy: 'by-episode' } },
36
     { path: '/:type/by-episode', component: listPage, props: { sidebar: true, sortBy: 'by-episode' } },
20
     { path: '/:type/by-artist', component: listPage, props: { sidebar: true, sortBy: 'by-artist' } },
37
     { path: '/:type/by-artist', component: listPage, props: { sidebar: true, sortBy: 'by-artist' } },
21
     // Single Pages
38
     // Single Pages

+ 25
- 6
vue-theme/src/utils/helpers.js Прегледај датотеку

7
     return type[type.length - 1] === 's' ? type.slice(0, -1) : type
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
 const sortTypes = {
10
 const sortTypes = {
16
     alpha: 'by-alpha',
11
     alpha: 'by-alpha',
17
     recent: 'by-recent',
12
     recent: 'by-recent',
18
     material: 'by-material',
13
     material: 'by-material',
14
+    artist: 'by-artist',
15
+    episode: 'by-episode',
19
 }
16
 }
20
 
17
 
21
 /**
18
 /**
23
  * This makes ALL post type modules available for the
20
  * This makes ALL post type modules available for the
24
  * list and single components to request data
21
  * list and single components to request data
25
  */
22
  */
26
- const postTypes = [
23
+const postTypes = [
27
     'episodes',
24
     'episodes',
28
     'artists',
25
     'artists',
29
     'exhibitions',
26
     'exhibitions',
32
     'pages',
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
 export { convertTitleCase, dePluralize, typeFromRoute, sortTypes, postTypes }
54
 export { convertTitleCase, dePluralize, typeFromRoute, sortTypes, postTypes }

Loading…
Откажи
Сачувај