Bladeren bron

:recycle: making galleries display images again

tags/0.9.0
j 5 jaren geleden
bovenliggende
commit
8cd5e01052
4 gewijzigde bestanden met toevoegingen van 10923 en 54 verwijderingen
  1. 10895
    9
      vue-theme/package-lock.json
  2. 8
    26
      vue-theme/src/components/gallery.vue
  3. 18
    17
      vue-theme/src/pages/single.vue
  4. 2
    2
      vue-theme/src/store/modules/media.js

+ 10895
- 9
vue-theme/package-lock.json
Diff onderdrukt omdat het te groot bestand
Bestand weergeven


+ 8
- 26
vue-theme/src/components/gallery.vue Bestand weergeven

3
     button(@click="hideGallery").hide hide
3
     button(@click="hideGallery").hide hide
4
 
4
 
5
     figure.f-col.center
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
     .controls.f-row
9
     .controls.f-row
10
-        button(@click="prev") left
10
+        button(v-if="selected > 0" @click="prev") previous
11
         .f-grow
11
         .f-grow
12
-        button(@click="next") right
12
+        button(v-if="selected < Object.values(images).length - 1" @click="next") next
13
 </template>
13
 </template>
14
 
14
 
15
 <script>
15
 <script>
17
 
17
 
18
 export default {
18
 export default {
19
     props: {
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
     data() { 
23
     data() { 
25
         return {
24
         return {
26
             selected: 0
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
     methods: {
28
     methods: {
46
         prev() {
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
         next() {
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
         hideGallery() {
35
         hideGallery() {
53
             this.$emit('close')
36
             this.$emit('close')
74
     async mounted() {
57
     async mounted() {
75
         // Set the first selection
58
         // Set the first selection
76
         this.selected = this.activeImageIndex
59
         this.selected = this.activeImageIndex
77
-        this.$store.dispatch(`getMediaById`, this.imageIds)
78
         window.addEventListener('keydown', this.interpretKeypress)
60
         window.addEventListener('keydown', this.interpretKeypress)
79
     },
61
     },
80
     unmounted() {
62
     unmounted() {

+ 18
- 17
vue-theme/src/pages/single.vue Bestand weergeven

7
 
7
 
8
         .post-single.block-wrapper(v-for="(block, i) in post.blocks" :key="`block-${i}`")
8
         .post-single.block-wrapper(v-for="(block, i) in post.blocks" :key="`block-${i}`")
9
             //- ?: are objects are always gallery blocks
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
                 p gallery number: {{ i }}
11
                 p gallery number: {{ i }}
12
                 ul
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
                 //- Fullscreen gallery
16
                 //- Fullscreen gallery
16
                 gallery(
17
                 gallery(
17
                     v-if="activeGalleryIndex == (i - 1)"
18
                     v-if="activeGalleryIndex == (i - 1)"
18
-                    :image-ids="post.galleries[block.gallery].ids"
19
                     :activeImageIndex="activeImageIndex"
19
                     :activeImageIndex="activeImageIndex"
20
                     v-on:close="activeGalleryIndex = -1"
20
                     v-on:close="activeGalleryIndex = -1"
21
-                    :image-sizes="post.attached"
21
+                    :images="imagesInGallery"
22
                 )
22
                 )
23
 
23
 
24
             //- Just a regular block
24
             //- Just a regular block
49
         return {
49
         return {
50
             images: [], 
50
             images: [], 
51
             activeGalleryIndex: -1,
51
             activeGalleryIndex: -1,
52
-            activeImageIndex: -1
52
+            activeImageID: -1
53
         }
53
         }
54
     },
54
     },
55
     computed: {
55
     computed: {
82
                 postsMap[post.slug] = post
82
                 postsMap[post.slug] = post
83
                 return postsMap
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
     methods: {
98
     methods: {
88
         openGallery(galleryIndex, imageID) {
99
         openGallery(galleryIndex, imageID) {
89
             this.activeGalleryIndex = galleryIndex
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
         checkAndSetHero(posts) {
103
         checkAndSetHero(posts) {
94
             const post = posts[this.$route.params.slug]
104
             const post = posts[this.$route.params.slug]
96
 
106
 
97
             const json = JSON.parse(post.hero)
107
             const json = JSON.parse(post.hero)
98
             this.$store.commit('SET_HERO', json)
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
     watch: {
111
     watch: {
112
             // this.checkForImages(newVal)
114
             // this.checkForImages(newVal)
113
             
115
             
114
             this.checkAndSetHero(newVal)
116
             this.checkAndSetHero(newVal)
115
-            this.checkAndSetImages(newVal)
116
         }
117
         }
117
     },
118
     },
118
     created() {
119
     created() {

+ 2
- 2
vue-theme/src/store/modules/media.js Bestand weergeven

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

Laden…
Annuleren
Opslaan