From 883b4fa97f69b0daa1440a72e2afe562767d2777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Sat, 9 Mar 2024 23:02:30 +0100 Subject: [PATCH] Init lightboxu az po otevreni fotky --- src/components/photos/PhotoGallery.vue | 121 +++++++++++------- src/composables/pagination.js | 2 + .../public/pilotProfile/FlightDetailPage.vue | 2 +- 3 files changed, 77 insertions(+), 48 deletions(-) diff --git a/src/components/photos/PhotoGallery.vue b/src/components/photos/PhotoGallery.vue index 49d12c5..cacdfdc 100644 --- a/src/components/photos/PhotoGallery.vue +++ b/src/components/photos/PhotoGallery.vue @@ -6,8 +6,9 @@ import PhotoSwipeDynamicCaption from "../../../node_modules/photoswipe-dynamic-c import PhotoCaption from "components/photos/PhotoCaption.vue"; import PhotoSwipeLightbox from "../../../node_modules/photoswipe/dist/photoswipe-lightbox.esm" import PhotoSwipe from "../../../node_modules/photoswipe/dist/photoswipe.esm" -import {useRoute, useRouter} from "vue-router"; +import {useRouter} from "vue-router"; import {usePhotosStore} from "stores/Photos"; +import {useQuasar} from "quasar"; const props = defineProps({ galleryId: { @@ -21,9 +22,8 @@ const props = defineProps({ } }) - -const route = useRoute(); const $router = useRouter(); +const $q = useQuasar(); let $lightbox = ref(null); @@ -46,18 +46,15 @@ const initLightbox = () => { $lightbox.value.init(); } +const isCollapsed = ref(true); +const photosCollapseLimit = computed(() => { + if ($q.screen.width <= $q.screen.sizes.sm) return 2; + else if ($q.screen.width <= $q.screen.sizes.md) return 3; + else return 4; +}); + onMounted(() => { - initLightbox(); - - // todo: tohle nefunguje, sice se galerie zavre, ale i tak se user presmeruje na predchozi stranku - window.onpopstate = function (e) { - if (!$lightbox.value || !$lightbox.value.pswp) { - initLightbox(); - } - - if ($lightbox.value && $lightbox.value.pswp) - $lightbox.value.pswp.close(); - }; + isCollapsed.value = props.photos.length >= photosCollapseLimit.value; }); onUnmounted(() => { @@ -69,7 +66,11 @@ onUnmounted(() => { const openedPhoto = computed(() => usePhotosStore().openedPhoto); watch(() => [openedPhoto.value, $lightbox.value], () => { - if (!$lightbox.value || !openedPhoto.value) return; + if (!openedPhoto.value) return; + + if (!$lightbox.value) { + initLightbox(); + } const idx = props.photos.findIndex(p => p.id === openedPhoto.value.id); if (idx >= 0) { @@ -77,47 +78,73 @@ watch(() => [openedPhoto.value, $lightbox.value], () => { usePhotosStore().setOpenedPhoto(null); } }, {immediate: true}); - -const isCollapsed = ref(false); - diff --git a/src/composables/pagination.js b/src/composables/pagination.js index b44b5c9..cd6ace4 100644 --- a/src/composables/pagination.js +++ b/src/composables/pagination.js @@ -1,6 +1,8 @@ import {ref} from "vue"; +// TODO: predelat na usePagination() composable! + export const paginationLimit = ref(10); export const paginationOffset = ref(0); diff --git a/src/pages/public/pilotProfile/FlightDetailPage.vue b/src/pages/public/pilotProfile/FlightDetailPage.vue index 33e219d..8e18bc8 100644 --- a/src/pages/public/pilotProfile/FlightDetailPage.vue +++ b/src/pages/public/pilotProfile/FlightDetailPage.vue @@ -89,7 +89,7 @@ useMeta(() => metaData({ - +