소스 검색

:sparkles: fixing gallery to work with new endpoint

tags/0.9.0
J 5 년 전
부모
커밋
a26e209f7c
3개의 변경된 파일36개의 추가작업 그리고 29개의 파일을 삭제
  1. 18
    20
      vue-theme/src/components/gallery.vue
  2. 17
    8
      vue-theme/src/pages/single.vue
  3. 1
    1
      vue-theme/src/utils/api.js

+ 18
- 20
vue-theme/src/components/gallery.vue 파일 보기

@@ -1,12 +1,11 @@
1 1
 <template lang="pug">
2 2
 .gallery.active.f-col.center
3 3
     button(@click="hideGallery").hide hide
4
-    p {{ imageIds }}
5
-    p image: {{ imageIds[selected] }}
6
-    ul
7
-        li(v-for="(image, i) of images" :class="{ active: i === selected }")
8
-            .image-wrapper.f-col.center
9
-                img(:src="image")
4
+
5
+    figure.f-col.center
6
+        img(v-if="selectedImageUrl" :src="selectedImageUrl")
7
+        p placeholder caption
8
+
10 9
     .controls.f-row
11 10
         button(@click="prev") left
12 11
         .f-grow
@@ -18,11 +17,21 @@ export default {
18 17
     props: {
19 18
         imageIds: { type: Array, required: true },
20 19
         activeImageIndex: { type: Number, default: 0 },
21
-        activeGalleryIndex: { type: Number },
20
+        imageSizes: { required: true }
22 21
     },
23 22
     data() { 
24 23
         return {
25
-            selected: -1
24
+            selected: 0
25
+        }
26
+    },
27
+    computed:{
28
+        selectedImageId() {
29
+            return this.imageIds[this.selected]
30
+        },
31
+        selectedImageUrl() {
32
+            const image = this.imageSizes[this.selectedImageId]
33
+            if(!image) return
34
+            return image.large
26 35
         }
27 36
     },
28 37
     methods: {
@@ -82,18 +91,7 @@ export default {
82 91
             z-index: 1011
83 92
         button.hide
84 93
             z-index: 1100
85
-        ul
86
-            list-style: none
87
-            li
88
-                display: none
89
-                &.active
90
-                    display: block
91
-                .image-wrapper
92
-                    height: 100%
93
-                    width: 50vw
94
-                    background-color: yellow
95
-                h1
96
-                    color: green
94
+
97 95
         .controls
98 96
             position: absolute
99 97
             width: 100vw

+ 17
- 8
vue-theme/src/pages/single.vue 파일 보기

@@ -8,7 +8,7 @@
8 8
 
9 9
         section(v-if="post")
10 10
             h4 {{ post.title }}
11
-            p {{ activeGalleryIndex }}
11
+
12 12
             .block-wrapper(v-for="(block, i) in post.blocks")
13 13
                     //- ?: are objects are always gallery blocks
14 14
                     .gallery.block(v-if="typeof block === 'object'")
@@ -19,20 +19,20 @@
19 19
                         //- Fullscreen gallery
20 20
                         gallery(
21 21
                             v-if="activeGalleryIndex == (i - 1)"
22
-                            :activeGalleryIndex="activeGalleryIndex"
23 22
                             :image-ids="post.galleries[block.gallery].ids"
24 23
                             :activeImageIndex="activeImageIndex"
25 24
                             v-on:close="activeGalleryIndex = -1"
25
+                            :image-sizes="post.attached"
26 26
                         )
27 27
 
28 28
                     //- Just a regular block
29 29
                     .block(v-else v-html="block")
30 30
 
31
-    //- sidebar(v-if="sidebar" :type="`${type}`")
32
-    //-     .shadow
33
-    //-         h1.t-up single slot
34
-    //-         div
35
-    //-             p body whatever
31
+    sidebar(v-if="sidebar" :type="`${type}`")
32
+        .shadow
33
+            h1.t-up single slot
34
+            div
35
+                p body whatever
36 36
 </template>
37 37
 
38 38
 <script>
@@ -100,6 +100,14 @@ export default {
100 100
 
101 101
             const json = JSON.parse(post.hero)
102 102
             this.$store.commit('SET_HERO', json)
103
+        },
104
+        async checkAndSetImages(posts) {
105
+            const post = posts[this.$route.params.slug]
106
+            if(!post || ! post.attached) return
107
+
108
+            const imagesAttached = post.attached
109
+            await this.$store.dispatch(`getMediaById`, imagesAttached)
110
+            console.log(this.$store.media)
103 111
         }
104 112
     },
105 113
     watch: {
@@ -108,11 +116,12 @@ export default {
108 116
             // this.checkForImages(newVal)
109 117
             
110 118
             this.checkAndSetHero(newVal)
119
+            this.checkAndSetImages(newVal)
111 120
         }
112 121
     },
113 122
     created() {
114 123
         let type = convertTitleCase(this.$route.params.type)
115
-        this.$store.dispatch(`getMediaById`, [7])
124
+        
116 125
         if(!this[`all{type}Loaded`]) {
117 126
             // console.log('Retrieving...', type)
118 127
             this.$store.dispatch(`getAll${type}`)

+ 1
- 1
vue-theme/src/utils/api.js 파일 보기

@@ -20,7 +20,7 @@ export default {
20 20
             }).catch(e => { cb(e) })
21 21
         }
22 22
     },
23
-    getSingleMedia(id) {
23
+    getSingleMedia(id, cb) {
24 24
         axios.get(SETTINGS.API_MEDIA_PATH + `${id}`).then(response => {
25 25
             cb(response.data)
26 26
         }).catch(e => { cb(e) })

Loading…
취소
저장