Просмотр исходного кода

:bug: adjusting computed post in template so it doesnt collide with state helper | #102

tags/0.9.0
J 4 лет назад
Родитель
Сommit
dbd5d73527
2 измененных файлов: 23 добавлений и 22 удалений
  1. 0
    2
      vue-theme/src/pages/mixin-post-types.js
  2. 23
    20
      vue-theme/src/pages/single.vue

+ 0
- 2
vue-theme/src/pages/mixin-post-types.js Просмотреть файл

@@ -1,5 +1,4 @@
1 1
 import { convertTitleCase, postTypes } from '@/utils/helpers'
2
-import { capitalize } from '@vue/shared'
3 2
 import { mapGetters, mapState } from 'vuex'
4 3
 
5 4
 /**
@@ -31,7 +30,6 @@ const stateHelper = {}
31 30
 for (let type of postTypes) {
32 31
     stateHelper[type] = type
33 32
 }
34
-
35 33
 const postTypeGetters = {
36 34
     computed: {
37 35
         ...mapGetters(getterHelper),

+ 23
- 20
vue-theme/src/pages/single.vue Просмотреть файл

@@ -2,25 +2,25 @@
2 2
 .page--single.f-col.between
3 3
     gallery(v-if="activeGalleryIndex >= 0" :activeImageIndex="activeImageIndex" :images="imagesInGallery" @close="closeGallery")
4 4
 
5
-    article.w-max(v-if="!post")
5
+    article.w-max(v-if="!singlePost")
6 6
         header
7 7
             p loading...
8 8
     article(v-else).w-max.f-grow.shadow
9 9
         header
10 10
             //- breadcrumb links at top of page, needs link routing
11
-            breadcrumb(:type="type" :post="post")
11
+            breadcrumb(:type="type" :post="singlePost")
12 12
             
13
-            h1.t-b  {{ post.title }}
14
-            //- p(v-if="post.categories") categories: {{ post.categories }}
15
-            //- p(v-if="post.type") type: {{ post.type }}
16
-            //- p(v-if="post.subtypes") subtypes: {{ post.subtypes }}
13
+            h1.t-b  {{ singlePost.title }}
14
+            //- p(v-if="singlePost.categories") categories: {{ singlePost.categories }}
15
+            //- p(v-if="singlePost.type") type: {{ singlePost.type }}
16
+            //- p(v-if="singlePost.subtypes") subtypes: {{ singlePost.subtypes }}
17 17
 
18 18
             .date-info(v-if="['exhibition', 'event'].includes(type)")
19
-                p start: {{ dateFrom(post.start) }}
20
-                p end: {{ dateFrom(post.end) }}
19
+                p start: {{ dateFrom(singlePost.start) }}
20
+                p end: {{ dateFrom(singlePost.end) }}
21 21
 
22 22
         //- WP main content
23
-        section.content(v-html="post.content")
23
+        section.content(v-html="singlePost.content")
24 24
 
25 25
         //- related artists section for episodes
26 26
         section(v-if="type === 'episode' && post" :post="post")
@@ -39,13 +39,14 @@
39 39
 </template>
40 40
 
41 41
 <script>
42
+import { mapGetters, mapState } from 'vuex'
42 43
 import card from '@/components/card.vue'
43 44
 import sidebar from '@/components/sidebars/sidebar'
44 45
 import gallery from '@/components/gallery/'
45 46
 import credits from '@/components/credits'
46 47
 import breadcrumb from '@/components/breadcrumb'
47 48
 
48
-import { postTypeGetters, scrollTop } from './mixin-post-types'
49
+import { postTypeGetters, stateHelper, scrollTop } from './mixin-post-types'
49 50
 
50 51
 import { convertTitleCase, dePluralize, typeFromRoute } from '@/utils/helpers'
51 52
 
@@ -72,8 +73,9 @@ export default {
72 73
         },
73 74
         /**
74 75
          * We get the actual post data using the slug
76
+         * Careful with name collisions with vuex helpers
75 77
          */
76
-        post() {
78
+        singlePost() {
77 79
             if (!this[this.type]) return
78 80
             const type = dePluralize(this.type)
79 81
 
@@ -87,20 +89,20 @@ export default {
87 89
         },
88 90
 
89 91
         idsForGallery() {
90
-            if (!this.post || this.activeGalleryIndex < 0) return []
91
-            return this.post.galleries[this.activeGalleryIndex].ids
92
+            if (!this.singlePost || this.activeGalleryIndex < 0) return []
93
+            return this.singlePost.galleries[this.activeGalleryIndex].ids
92 94
         },
93 95
         /**
94 96
          * We need a convenient way to get all the images
95 97
          * broken down by gallery. We use the active gallery
96 98
          * image IDs to create a map. We match the ID to the
97
-         * image size and url information returned by post.attached
99
+         * image size and url information returned by singlePost.attached
98 100
          */
99 101
         imagesInGallery() {
100 102
             if (!this.activeGalleryIndex < 0) return {}
101 103
 
102 104
             return this.idsForGallery.reduce((imageMap, id) => {
103
-                imageMap[id] = this.post.attached[parseInt(id)]
105
+                imageMap[id] = this.singlePost.attached[parseInt(id)]
104 106
                 return imageMap
105 107
             }, {})
106 108
         },
@@ -110,8 +112,8 @@ export default {
110 112
             )
111 113
         },
112 114
         p2pPostsByType() {
113
-            return this.post
114
-                ? Object.values(this.post.relatedto).reduce(
115
+            return this.singlePost
116
+                ? Object.values(this.singlePost.relatedto).reduce(
115 117
                       (byType, relatedPost) => {
116 118
                           if (!byType[relatedPost.type])
117 119
                               byType[relatedPost.type] = []
@@ -132,7 +134,7 @@ export default {
132 134
          * @param {string} imageInfo
133 135
          */
134 136
         openGallery(imageInfo) {
135
-            const byIndex = this.post.galleries.reduce(
137
+            const byIndex = this.singlePost.galleries.reduce(
136 138
                 (byIndex, gallery, index) => {
137 139
                     byIndex[index] = gallery.ids
138 140
                     return byIndex
@@ -196,7 +198,8 @@ export default {
196 198
              * !: posts watcher fires when this finishes
197 199
              */
198 200
             let type = convertTitleCase(this.type) + 's'
199
-            // modules are NOT plural for some reason
201
+
202
+            // modules are NOT plural because module key
200 203
             if (!this.$store.state[this.type]) return
201 204
             let allPostsOfType = this.$store.state[this.type].all
202 205
 
@@ -252,7 +255,7 @@ export default {
252 255
     },
253 256
     async created() {
254 257
         await this.loadPostData()
255
-        this.checkAndSetHero(this.post)
258
+        this.checkAndSetHero(this.singlePost)
256 259
     },
257 260
 }
258 261
 </script>

Загрузка…
Отмена
Сохранить