Browse Source

:recycle: page sort/load fixes | sidebar post loading

tags/0.9.0
j 4 years ago
parent
commit
77e3cd9e33

+ 46
- 15
vue-theme/src/components/sidebars/events.vue View File

@@ -1,18 +1,49 @@
1 1
 <template lang="pug">
2
-//- most recent upcoming events - sidebar in exhibition list - max=2?
3
-h3.t-up upcoming events
2
+//- most recent upcoming event - sidebar in events list - max=2?
3
+h3.t-up {{ listType }} events
4 4
 ul.t-up
5
-    li
6
-        img(src="https://i2.wp.com/www.craftinamerica.org/wp-content/uploads/2021/10/IMG_9399edit.jpg?fit=640%2C361&ssl=1")
7
-        p event title link 
8
-        p date
9
-        p date from  -  date to
10
-        p 
11
-    li
12
-        img(src="https://i2.wp.com/www.craftinamerica.org/wp-content/uploads/2021/10/IMG_9399edit.jpg?fit=640%2C361&ssl=1")
13
-        p event title link 
14
-        p date
15
-        p date from  -  date todate
16
-        p 
5
+    li(v-for="post in events")
6
+        featured-image(:post="post", thumbsize="'standard'")
7
+        router-link(:to="`/events/${post.slug}`")
8
+            p.t-up {{ post.title }}
9
+        p {{ post.start }} &ndash; {{ post.end }}
10
+</template>
17 11
 
18
-</template>
12
+<script>
13
+import featuredImage from '@/components/featured-image'
14
+import { postTypeGetters } from '@/pages/mixin-post-types'
15
+import { sortTypes } from '@/utils/helpers'
16
+
17
+export default {
18
+    mixins: [postTypeGetters],
19
+    components: { featuredImage },
20
+    computed: {
21
+        loaded() {
22
+            return this[`allEventsLoaded`]
23
+        },
24
+        events() {
25
+            return this[`upcomingAndCurrentEvents`]
26
+        },
27
+    },
28
+    data() {
29
+        return {
30
+            listType: 'upcoming',
31
+        }
32
+    },
33
+    methods: {
34
+        async getPosts() {
35
+            const upcoming = this.$store.dispatch(
36
+                `getAllEvents`,
37
+                sortTypes.currentAndUpcoming,
38
+            )
39
+            if (upcoming.length < 1) {
40
+                // this.listType = 'past'
41
+                // this.$store.dispatch(`getAllEvents`, sortTypes.past)
42
+            }
43
+        },
44
+    },
45
+    created() {
46
+        if (!this.loaded) this.getPosts()
47
+    },
48
+}
49
+</script>

+ 41
- 21
vue-theme/src/components/sidebars/exhibitions.vue View File

@@ -1,29 +1,49 @@
1 1
 <template lang="pug">
2 2
 //- most recent upcoming exhibition - sidebar in events list - max=2?
3
-h3.t-up upcoming exhibitions
3
+h3.t-up {{ listType }} exhibitions
4 4
 ul.t-up
5
-    li
6
-        img(src="https://i1.wp.com/www.craftinamerica.org/wp-content/uploads/2021/10/DSC_0382edit-1.jpg?fit=640%2C361&ssl=1")
7
-        p exhibition title link
8
-        p date from  -  date to
9
-        p 
10
-    li
11
-        img(src="https://i1.wp.com/www.craftinamerica.org/wp-content/uploads/2021/10/DSC_0382edit-1.jpg?fit=640%2C361&ssl=1")
12
-        p exhibition title link
13
-        p date from  -  date to
14
-        p 
15
-
5
+    li(v-for="post in exhibitions")
6
+        featured-image(:post="post", thumbsize="'standard'")
7
+        router-link(:to="`/exhibitions/${post.slug}`")
8
+            p.t-up {{ post.title }}
9
+        p {{ post.start }} &ndash; {{ post.end }}
16 10
 </template>
17 11
 
18 12
 <script>
13
+import featuredImage from '@/components/featured-image'
14
+import { postTypeGetters } from '@/pages/mixin-post-types'
15
+import { sortTypes } from '@/utils/helpers'
16
+
19 17
 export default {
20
-    props: {
21
-        postsByType:{
22
-            type: Array
23
-        }, 
24
-        postType:{
25
-            type: String
26
-        }, 
27
-    }
18
+    mixins: [postTypeGetters],
19
+    components: { featuredImage },
20
+    computed: {
21
+        loaded() {
22
+            return this[`allExhibitionsLoaded`]
23
+        },
24
+        exhibitions() {
25
+            return this[`upcomingAndCurrentExhibitions`]
26
+        },
27
+    },
28
+    data() {
29
+        return {
30
+            listType: 'upcoming',
31
+        }
32
+    },
33
+    methods: {
34
+        async getPosts() {
35
+            const upcoming = this.$store.dispatch(
36
+                `getAllExhibitions`,
37
+                sortTypes.currentAndUpcoming,
38
+            )
39
+            if (upcoming.length < 1) {
40
+                // this.listType = 'past'
41
+                // this.$store.dispatch(`getAllExhibitions`, sortTypes.past)
42
+            }
43
+        },
44
+    },
45
+    created() {
46
+        if (!this.loaded) this.getPosts()
47
+    },
28 48
 }
29
-</script>
49
+</script>

+ 4
- 5
vue-theme/src/components/sidebars/sidebar.vue View File

@@ -46,12 +46,11 @@ aside.sidebar
46 46
         slot
47 47
 
48 48
         //- single layout Exhibitions sidebar
49
-        .shadow(v-if="layout === 'single'")
50
-            exhibitions-sidebar
51
-        
52
-        //- single layout Events sindebar
53
-        .shadow(v-if="layout === 'single'")
49
+        .shadow(v-if="type === 'exhibitions' && layout === 'single'")
54 50
             events-sidebar
51
+        //- single layout Events sindebar
52
+        .shadow(v-if="type === 'events' && layout === 'single'")
53
+            exhibitions-sidebar
55 54
 
56 55
         //- list layout Exhibition sidebar show events
57 56
         .shadow(v-if="type === 'exhibitions' && layout === 'list'")

+ 36
- 7
vue-theme/src/pages/list.vue View File

@@ -66,9 +66,11 @@ export default {
66 66
             // Sorting
67 67
             let sort = this.sortBy
68 68
                 ? this.sortBy
69
-                : this.$route.path.split('/').pop()
69
+                : this.$route.path
70
+                      .split('/')
71
+                      .filter(p => p)
72
+                      .pop()
70 73
             // !: BUG
71
-            // if(this.type !== sort || !Object.values(sortTypes).includes(sort)) sort = null
72 74
             // if (Object.values(sortTypes).includes(sort)) {
73 75
             //     console.log('trying to sort by:', sort)
74 76
             //     console.log(
@@ -77,9 +79,28 @@ export default {
77 79
             //     )
78 80
             // }
79 81
 
82
+            if (!Object.values(sortTypes).includes(sort)) {
83
+                console.log('Sort not found:', sort)
84
+                sort = null
85
+            }
86
+
80 87
             // Don't dispatch if there's no type
81 88
             if (this.type && this.dispatchName) {
89
+                console.log('Gettings posts:', this.type, this.dispatchName)
82 90
                 this.$store.dispatch(this.dispatchName, sort)
91
+
92
+                if (this.type == 'events') {
93
+                    this.$store.dispatch(
94
+                        'getAllExhibitions',
95
+                        sortTypes.currentAndUpcoming,
96
+                    )
97
+                }
98
+                if (this.type == 'exhibitions') {
99
+                    this.$store.dispatch(
100
+                        'getAllEvents',
101
+                        sortTypes.currentAndUpcoming,
102
+                    )
103
+                }
83 104
             }
84 105
         },
85 106
         async checkAndSetHero(type) {
@@ -117,10 +138,20 @@ export default {
117 138
         async $route(to, from) {
118 139
             // console.log(this.sidebar)
119 140
             let type = convertTitleCase(this.type)
120
-            let sort = this.sortBy ? this.sortBy : to.path.split('/').pop()
141
+            let sort = to.path
142
+                .split('/')
143
+                .filter(p => p)
144
+                .pop()
121 145
             this.checkAndSetHero(this.type)
122
-            // console.log('---')
123
-            // console.log(sort)
146
+
147
+            // console.log('---', sort, type)
148
+            // console.log(`${from.path}>>>${to.path}`)
149
+            if (!Object.values(sortTypes).includes(sort)) {
150
+                console.log('sort not found:', sort)
151
+                sort = null
152
+            }
153
+            // console.log('---', sort, type)
154
+
124 155
             if (!this[`all${type}Loaded`] || sort) this.getPosts()
125 156
         },
126 157
     },
@@ -131,8 +162,6 @@ export default {
131 162
     },
132 163
     created() {
133 164
         let type = convertTitleCase(this.type)
134
-        // console.log(`${type} already loaded?:`, this[`all${type}Loaded`])
135
-
136 165
         this.checkAndSetHero(this.type)
137 166
 
138 167
         if (!this[`all${type}Loaded`]) this.getPosts()

+ 4
- 0
vue-theme/src/pages/mixin-post-types.js View File

@@ -13,6 +13,10 @@ for (let type of postTypes) {
13 13
     getterHelper[`all${capitalized}`] = `all${capitalized}`
14 14
     getterHelper[`all${capitalized}Loaded`] = `all${capitalized}Loaded`
15 15
 }
16
+getterHelper[`upcomingAndCurrentEvents`] = `upcomingAndCurrentEvents`
17
+getterHelper[`pastEvents`] = `pastEvents`
18
+getterHelper[`upcomingAndCurrentExhibitions`] = `upcomingAndCurrentExhibitions`
19
+getterHelper[`pastExhibitions`] = `pastExhibitions`
16 20
 
17 21
 const stateHelper = {}
18 22
 for (let type of postTypes) {

+ 7
- 3
vue-theme/src/router/routes.js View File

@@ -11,14 +11,13 @@ export default [
11 11
     {
12 12
         path: '/episodes',
13 13
         component: listPage,
14
-        props: { sidebar: false, grid: true },
14
+        props: { sidebar: false, grid: true, sortBy: null },
15 15
     },
16 16
     {
17 17
         path: '/artists',
18 18
         component: listPage,
19
-        props: { sidebar: true, grid: true },
19
+        props: { sidebar: true, grid: true, sortBy: null },
20 20
     },
21
-    { path: '/:type', component: listPage, props: { sidebar: true } },
22 21
     // Sorted List Pages
23 22
     {
24 23
         path: `/artists/${sortTypes.alpha}`,
@@ -70,6 +69,11 @@ export default [
70 69
         component: listPage,
71 70
         props: { sidebar: true, sortBy: 'by-artist' },
72 71
     },
72
+    {
73
+        path: '/:type',
74
+        component: listPage,
75
+        props: { sidebar: true, sortBy: null },
76
+    },
73 77
     // Single Pages
74 78
     { path: '/:type/:slug', component: singlePage, props: { sidebar: true } },
75 79
 ]

+ 12
- 0
vue-theme/src/store/modules/event.js View File

@@ -9,6 +9,18 @@ const state = {
9 9
 const getters = {
10 10
     allEvents: state => state.all,
11 11
     allEventsLoaded: state => state.loaded,
12
+    pastEvents: state => {
13
+        const now = new Date()
14
+        return state.all.filter(event => {
15
+            return parseInt(event.end) > now
16
+        })
17
+    },
18
+    upcomingAndCurrentEvents: state => {
19
+        const now = new Date()
20
+        return state.all.filter(event => {
21
+            return parseInt(event.end) <= now
22
+        })
23
+    },
12 24
 }
13 25
 
14 26
 const actions = {

+ 14
- 1
vue-theme/src/store/modules/exhibition.js View File

@@ -1,5 +1,4 @@
1 1
 import api from '../../utils/api'
2
-import { sortTypes } from '../../utils/helpers'
3 2
 
4 3
 const state = {
5 4
     all: [],
@@ -10,6 +9,20 @@ const state = {
10 9
 const getters = {
11 10
     allExhibitions: state => state.all,
12 11
     allExhibitionsLoaded: state => state.loaded,
12
+    pastExhibitions: state => {
13
+        return state.all.filter(exhibition => {
14
+            const now = new Date()
15
+            return parseInt(exhibition.end) > now
16
+        })
17
+    },
18
+    upcomingAndCurrentExhibitions: state => {
19
+        return state.all
20
+        // return state.all.filter(exhibition => {
21
+        //     const now = new Date()
22
+        //     // return parseInt(exhibition.end) <= now
23
+        //     return parseInt(exhibition.end) <= now
24
+        // })
25
+    },
13 26
 }
14 27
 
15 28
 const actions = {

Loading…
Cancel
Save