From b00bc1594fbf62f549e5c244622f065b50b5e5a1 Mon Sep 17 00:00:00 2001 From: jlpereira Date: Wed, 20 Sep 2023 12:03:41 -0300 Subject: [PATCH] Add mosaic component --- .../GalleryCarousel.global.vue | 56 +++++--------- .../GalleryMosaic/GalleryMosaic.global.vue | 73 +++++++++++++++++++ src/components/Gallery/useGallery.js | 49 +++++++++++++ 3 files changed, 141 insertions(+), 37 deletions(-) create mode 100644 src/components/Gallery/GalleryMosaic/GalleryMosaic.global.vue create mode 100644 src/components/Gallery/useGallery.js diff --git a/src/components/Gallery/GalleryCarousel/GalleryCarousel.global.vue b/src/components/Gallery/GalleryCarousel/GalleryCarousel.global.vue index 0a500c5..f8f1eed 100644 --- a/src/components/Gallery/GalleryCarousel/GalleryCarousel.global.vue +++ b/src/components/Gallery/GalleryCarousel/GalleryCarousel.global.vue @@ -5,10 +5,10 @@ > @@ -37,8 +37,8 @@ diff --git a/src/components/Gallery/useGallery.js b/src/components/Gallery/useGallery.js new file mode 100644 index 0000000..8493b40 --- /dev/null +++ b/src/components/Gallery/useGallery.js @@ -0,0 +1,49 @@ +import { ref, watch } from 'vue' +import { makeAPIRequest } from '@/utils' + +export function useGallery({ props }) { + const depictions = ref([]) + + function makeGalleryImage(depiction) { + return { + id: depiction.id, + objectId: depiction.depiction_object_id, + objectType: depiction.depiction_object_type, + objectLabel: depiction.depiction_object.label, + label: depiction.label, + imageOriginal: depiction.image.original, + imageMedium: depiction.image.medium, + attribution: depiction.attribution?.label || '', + labelAttribution: [ + depiction.depiction_object.label, + depiction.attribution?.label || '' + ].join(' ') + } + } + + watch( + () => props.depictionId, + (ids) => { + if (ids.length) { + makeAPIRequest + .get('/depictions/gallery', { + params: { depiction_id: ids } + }) + .then(({ data }) => { + depictions.value = data + .map(makeGalleryImage) + .sort( + (a, b) => + props.depictionId.indexOf(a.id) - + props.depictionId.indexOf(b.id) + ) + }) + } + }, + { immediate: true } + ) + + return { + depictions + } +}