Bläddra i källkod

:recycle: making galleries display images again

tags/0.9.0
j 5 år sedan
förälder
incheckning
8cd5e01052

+ 10895
- 9
vue-theme/package-lock.json
Filskillnaden har hållits tillbaka eftersom den är för stor
Visa fil


+ 8
- 26
vue-theme/src/components/gallery.vue Visa fil

@@ -3,13 +3,13 @@
3 3
     button(@click="hideGallery").hide hide
4 4
 
5 5
     figure.f-col.center
6
-        img(v-if="selectedImageUrl" :src="selectedImageUrl")
7
-        p placeholder caption
6
+        img(v-if="Object.values(images).length > 0" :src="Object.values(images)[selected]['large']")
7
+        p active: {{ selected }}
8 8
 
9 9
     .controls.f-row
10
-        button(@click="prev") left
10
+        button(v-if="selected > 0" @click="prev") previous
11 11
         .f-grow
12
-        button(@click="next") right
12
+        button(v-if="selected < Object.values(images).length - 1" @click="next") next
13 13
 </template>
14 14
 
15 15
 <script>
@@ -17,37 +17,20 @@ import { mapGetters } from 'vuex'
17 17
 
18 18
 export default {
19 19
     props: {
20
-        imageIds: { type: Array, required: true },
21
-        activeImageIndex: { type: Number, default: 0 },
22
-        imageSizes: { required: true }
20
+        activeImageIndex: { type: Number, required: true, default: 0 },
21
+        images: { type: Object, required: true }
23 22
     },
24 23
     data() { 
25 24
         return {
26 25
             selected: 0
27 26
         }
28 27
     },
29
-    computed:{
30
-        selectedImageId() {
31
-            return this.imageIds[this.selected]
32
-        },
33
-        selectedImageUrl() {
34
-            const image = this.imageSizes[this.selectedImageId]
35
-            if(!image) return
36
-            return image.large
37
-        }
38
-    },
39
-    computed: {
40
-        ...mapGetters({
41
-            allMedia: 'allMedia',
42
-            allMediaLoaded: 'allMediaLoaded',
43
-        })
44
-    },
45 28
     methods: {
46 29
         prev() {
47
-            this.selected > 0 ? this.selected-- : this.selected = this.imageIds.length - 1
30
+            this.selected > 0 ? this.selected-- : this.selected = Object.keys(this.images).length - 1
48 31
         },
49 32
         next() {
50
-            this.selected < this.imageIds.length - 1 ? this.selected++ : this.selected = 0
33
+            this.selected < Object.keys(this.images).length - 1 ? this.selected++ : this.selected = 0
51 34
         },
52 35
         hideGallery() {
53 36
             this.$emit('close')
@@ -74,7 +57,6 @@ export default {
74 57
     async mounted() {
75 58
         // Set the first selection
76 59
         this.selected = this.activeImageIndex
77
-        this.$store.dispatch(`getMediaById`, this.imageIds)
78 60
         window.addEventListener('keydown', this.interpretKeypress)
79 61
     },
80 62
     unmounted() {

+ 18
- 17
vue-theme/src/pages/single.vue Visa fil

@@ -7,18 +7,18 @@
7 7
 
8 8
         .post-single.block-wrapper(v-for="(block, i) in post.blocks" :key="`block-${i}`")
9 9
             //- ?: are objects are always gallery blocks
10
-            .gallery.block(v-if="typeof block === 'object'")
10
+            .gallery.block(v-if="typeof block === 'object'" :class="`gallery-${i}`")
11 11
                 p gallery number: {{ i }}
12 12
                 ul
13
-                    li(v-for="(imageID, j) in post.galleries[block.gallery].ids") 
14
-                        button(@click="openGallery(i - 1, j)") gallery: {{ i }} image: {{ imageID }}
13
+                    li(v-for="(imageID, j) in post.galleries[block.gallery].ids" :class="`gallery-${i}--image-${j+1}`" :key="`block-${i}-${j}`")
14
+                        img(@click="openGallery(i - 1, imageID)" :src="post.attached[imageID]['thumbnail']")
15
+                        button(@click="openGallery(i - 1, imageID)") gallery: {{ i }} image: {{ imageID }}
15 16
                 //- Fullscreen gallery
16 17
                 gallery(
17 18
                     v-if="activeGalleryIndex == (i - 1)"
18
-                    :image-ids="post.galleries[block.gallery].ids"
19 19
                     :activeImageIndex="activeImageIndex"
20 20
                     v-on:close="activeGalleryIndex = -1"
21
-                    :image-sizes="post.attached"
21
+                    :images="imagesInGallery"
22 22
                 )
23 23
 
24 24
             //- Just a regular block
@@ -49,7 +49,7 @@ export default {
49 49
         return {
50 50
             images: [], 
51 51
             activeGalleryIndex: -1,
52
-            activeImageIndex: -1
52
+            activeImageID: -1
53 53
         }
54 54
     },
55 55
     computed: {
@@ -82,13 +82,23 @@ export default {
82 82
                 postsMap[post.slug] = post
83 83
                 return postsMap
84 84
             }, {})
85
+        },
86
+        imagesInGallery() {
87
+            if(!this.activeGalleryIndex < 0) return {}
88
+            
89
+            return this.post.galleries[this.activeGalleryIndex].ids.reduce((imageMap, id) => {
90
+                imageMap[id] = this.post.attached[id]
91
+                return imageMap
92
+            }, {})
93
+        },
94
+        activeImageIndex() {
95
+            return Object.keys(this.imagesInGallery).indexOf(this.activeImageID.toString())
85 96
         }
86 97
     },
87 98
     methods: {
88 99
         openGallery(galleryIndex, imageID) {
89 100
             this.activeGalleryIndex = galleryIndex
90
-            this.activeImageIndex = imageID ? imageID : 0
91
-            // console.log(this.post.galleries[galleryIndex])
101
+            this.activeImageID = imageID ? imageID : 0
92 102
         },
93 103
         checkAndSetHero(posts) {
94 104
             const post = posts[this.$route.params.slug]
@@ -96,14 +106,6 @@ export default {
96 106
 
97 107
             const json = JSON.parse(post.hero)
98 108
             this.$store.commit('SET_HERO', json)
99
-        },
100
-        async checkAndSetImages(posts) {
101
-            const post = posts[this.$route.params.slug]
102
-            if(!post || ! post.attached) return
103
-
104
-            const imagesAttached = post.attached
105
-            await this.$store.dispatch(`getMediaById`, imagesAttached)
106
-            console.log(this.$store.media)
107 109
         }
108 110
     },
109 111
     watch: {
@@ -112,7 +114,6 @@ export default {
112 114
             // this.checkForImages(newVal)
113 115
             
114 116
             this.checkAndSetHero(newVal)
115
-            this.checkAndSetImages(newVal)
116 117
         }
117 118
     },
118 119
     created() {

+ 2
- 2
vue-theme/src/store/modules/media.js Visa fil

@@ -1,7 +1,7 @@
1 1
 import api from '../../utils/api'
2 2
 
3 3
 const state = {
4
-    all: {},
4
+    all: [],
5 5
     loaded: false,
6 6
 }
7 7
 
@@ -27,7 +27,7 @@ const actions = {
27 27
 }
28 28
 
29 29
 const mutations = {
30
-    STORE_FETCHED_MEDIA(state, { media }) { state.all = media },
30
+    STORE_FETCHED_MEDIA(state, { media }) { state.all.push() },
31 31
     CLEAR_MEDIA(state) { state.all = [] },
32 32
     MEDIA_LOADED(state, val) { state.loaded = val },
33 33
 }

Laddar…
Avbryt
Spara