|
|
@@ -31,15 +31,11 @@ import sidebar from '@/components/sidebars/sidebar'
|
|
31
|
31
|
import { convertTitleCase, typeFromRoute, sortTypes } from '@/utils/helpers'
|
|
32
|
32
|
|
|
33
|
33
|
export default {
|
|
|
34
|
+ components: { sidebar },
|
|
34
|
35
|
props: {
|
|
35
|
|
- sidebar: {
|
|
36
|
|
- type: Boolean
|
|
37
|
|
- },
|
|
38
|
|
- sortBy: {
|
|
39
|
|
- type: String
|
|
40
|
|
- }
|
|
|
36
|
+ sidebar: { type: Boolean },
|
|
|
37
|
+ sortBy: { type: String }
|
|
41
|
38
|
},
|
|
42
|
|
- components: { sidebar },
|
|
43
|
39
|
computed: {
|
|
44
|
40
|
...mapGetters({
|
|
45
|
41
|
allPages: 'allPages',
|
|
|
@@ -66,15 +62,21 @@ export default {
|
|
66
|
62
|
},
|
|
67
|
63
|
posts() {
|
|
68
|
64
|
let type = convertTitleCase(this.type)
|
|
69
|
|
-
|
|
70
|
|
- // We're override the API to sort by date
|
|
71
|
|
- // because items are returned by ID
|
|
|
65
|
+ if(!type) return
|
|
|
66
|
+
|
|
|
67
|
+ /**
|
|
|
68
|
+ * We override the API to sort by date
|
|
|
69
|
+ * because items are returned by ID so
|
|
|
70
|
+ * we need to resort it by date
|
|
|
71
|
+ */
|
|
72
|
72
|
let unsortedOfType = Object.values(this[`all${type}`])
|
|
73
|
|
- let sortedByRecent = unsortedOfType.sort((postA, postB) => {
|
|
74
|
|
- return new Date(postB.date) - new Date(postA.date)
|
|
75
|
|
- })
|
|
|
73
|
+ let sortedByRecent = unsortedOfType.sort((postA, postB) => new Date(postB.date) - new Date(postA.date))
|
|
76
|
74
|
|
|
77
|
|
- // !: Sorting of this[`all${type}`] is controlled by API
|
|
|
75
|
+ /**
|
|
|
76
|
+ * Sorting of this[`all${type}`] is also controlled by API
|
|
|
77
|
+ * so if a sortBy is specified we return it sorted or
|
|
|
78
|
+ * we fail over to sorted by date
|
|
|
79
|
+ */
|
|
78
|
80
|
return this.sortBy ? this[`all${type}`] : sortedByRecent
|
|
79
|
81
|
},
|
|
80
|
82
|
},
|