Преглед на файлове

: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
 <template lang="pug">
1
 <template lang="pug">
2
 .gallery.active.f-col.center
2
 .gallery.active.f-col.center
3
     button(@click="hideGallery").hide hide
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
     .controls.f-row
9
     .controls.f-row
11
         button(@click="prev") left
10
         button(@click="prev") left
12
         .f-grow
11
         .f-grow
18
     props: {
17
     props: {
19
         imageIds: { type: Array, required: true },
18
         imageIds: { type: Array, required: true },
20
         activeImageIndex: { type: Number, default: 0 },
19
         activeImageIndex: { type: Number, default: 0 },
21
-        activeGalleryIndex: { type: Number },
20
+        imageSizes: { required: true }
22
     },
21
     },
23
     data() { 
22
     data() { 
24
         return {
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
     methods: {
37
     methods: {
82
             z-index: 1011
91
             z-index: 1011
83
         button.hide
92
         button.hide
84
             z-index: 1100
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
         .controls
95
         .controls
98
             position: absolute
96
             position: absolute
99
             width: 100vw
97
             width: 100vw

+ 17
- 8
vue-theme/src/pages/single.vue Целия файл

8
 
8
 
9
         section(v-if="post")
9
         section(v-if="post")
10
             h4 {{ post.title }}
10
             h4 {{ post.title }}
11
-            p {{ activeGalleryIndex }}
11
+
12
             .block-wrapper(v-for="(block, i) in post.blocks")
12
             .block-wrapper(v-for="(block, i) in post.blocks")
13
                     //- ?: are objects are always gallery blocks
13
                     //- ?: are objects are always gallery blocks
14
                     .gallery.block(v-if="typeof block === 'object'")
14
                     .gallery.block(v-if="typeof block === 'object'")
19
                         //- Fullscreen gallery
19
                         //- Fullscreen gallery
20
                         gallery(
20
                         gallery(
21
                             v-if="activeGalleryIndex == (i - 1)"
21
                             v-if="activeGalleryIndex == (i - 1)"
22
-                            :activeGalleryIndex="activeGalleryIndex"
23
                             :image-ids="post.galleries[block.gallery].ids"
22
                             :image-ids="post.galleries[block.gallery].ids"
24
                             :activeImageIndex="activeImageIndex"
23
                             :activeImageIndex="activeImageIndex"
25
                             v-on:close="activeGalleryIndex = -1"
24
                             v-on:close="activeGalleryIndex = -1"
25
+                            :image-sizes="post.attached"
26
                         )
26
                         )
27
 
27
 
28
                     //- Just a regular block
28
                     //- Just a regular block
29
                     .block(v-else v-html="block")
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
 </template>
36
 </template>
37
 
37
 
38
 <script>
38
 <script>
100
 
100
 
101
             const json = JSON.parse(post.hero)
101
             const json = JSON.parse(post.hero)
102
             this.$store.commit('SET_HERO', json)
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
     watch: {
113
     watch: {
108
             // this.checkForImages(newVal)
116
             // this.checkForImages(newVal)
109
             
117
             
110
             this.checkAndSetHero(newVal)
118
             this.checkAndSetHero(newVal)
119
+            this.checkAndSetImages(newVal)
111
         }
120
         }
112
     },
121
     },
113
     created() {
122
     created() {
114
         let type = convertTitleCase(this.$route.params.type)
123
         let type = convertTitleCase(this.$route.params.type)
115
-        this.$store.dispatch(`getMediaById`, [7])
124
+        
116
         if(!this[`all{type}Loaded`]) {
125
         if(!this[`all{type}Loaded`]) {
117
             // console.log('Retrieving...', type)
126
             // console.log('Retrieving...', type)
118
             this.$store.dispatch(`getAll${type}`)
127
             this.$store.dispatch(`getAll${type}`)

+ 1
- 1
vue-theme/src/utils/api.js Целия файл

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

Loading…
Отказ
Запис