mirror of
https://github.com/storytold/artcraft.git
synced 2026-10-20 17:02:53 -04:00
fix lightbox carousel not loading on second open
This commit is contained in:
@@ -790,9 +790,14 @@ export const GalleryModal = React.memo(
|
||||
|
||||
useSignals();
|
||||
|
||||
// Synchronize lightbox image when external media id signal is set
|
||||
// Synchronize lightbox image when external media id signal is set.
|
||||
// Skip if the signal already carries carousel data (imageUrls / batchImageToken)
|
||||
// set by the caller (e.g. TextToImage batch, TaskQueue) — overwriting it with
|
||||
// the plain gallery item would strip those fields and break the carousel.
|
||||
useEffect(() => {
|
||||
if (galleryModalLightboxMediaId.value && allItems.length > 0) {
|
||||
const current = lightboxImageSignal.value as any;
|
||||
if (current?.imageUrls?.length > 0 || current?.batchImageToken) return;
|
||||
const target = allItems.find(
|
||||
(it) => it.id === galleryModalLightboxMediaId.value,
|
||||
);
|
||||
|
||||
@@ -389,6 +389,12 @@ export function LightboxModal({
|
||||
emblaMainApi.on("select", onSelect).on("reInit", onSelect);
|
||||
}, [emblaMainApi, onSelect]);
|
||||
|
||||
// Re-initialize Embla when slides change so it picks up the new DOM children
|
||||
useEffect(() => {
|
||||
emblaMainApi?.reInit();
|
||||
emblaThumbsApi?.reInit();
|
||||
}, [effectiveImageUrls, emblaMainApi, emblaThumbsApi]);
|
||||
|
||||
useEffect(() => {
|
||||
const idx = initialIndex ?? 0;
|
||||
setSelectedIndex(idx);
|
||||
|
||||
Reference in New Issue
Block a user