Skip to content

Commit

Permalink
Update current image index on product gallery slide
Browse files Browse the repository at this point in the history
  • Loading branch information
futurGH committed Nov 14, 2023
1 parent f9dd3d6 commit 2146b66
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/components/product/ProductGallery.client.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import clsx from "clsx";
import { RefObject, useState } from "react";
import ImageGallery, { type ReactImageGalleryItem } from "react-image-gallery";
import { ExpandIcon } from "../../assets/icons/expand";
import { MinimizeIcon } from "../../assets/icons/minimize";
import { PrintFillIcon } from "../../assets/icons/print-fill";
import { MediaContentType } from "../../graphql/storefront.generated";
import type { MediaFragment, MediaImage } from "../../graphql/storefront.generated";
import type { RefObject } from "react";

interface ProductGalleryProps {
media: Array<MediaFragment>;
Expand Down Expand Up @@ -44,7 +44,9 @@ export function ProductGallery({ media, galleryRef }: ProductGalleryProps) {
thumbnailWidth: previewImage?.width || undefined,
thumbnailAlt: previewImage?.altText || undefined,
}));
const currentImageIsRender = items[galleryRef.current?.getCurrentIndex() ?? -1]?.originalAlt?.startsWith("RENDER:");
const [currentIndex, setCurrentIndex] = useState(0);
const currentImage = items[currentIndex];
const currentImageIsRender = currentImage?.originalAlt?.startsWith("RENDER:");
return (
<div className="relative h-fit w-full md:mt-16">
{currentImageIsRender ? <RenderBadge /> : null}
Expand All @@ -54,6 +56,7 @@ export function ProductGallery({ media, galleryRef }: ProductGalleryProps) {
lazyLoad={true}
showNav={false}
showPlayButton={false}
onBeforeSlide={(currentIndex) => setCurrentIndex(currentIndex)}
renderFullscreenButton={(onClick, isFullscreen) => {
const FullscreenIcon = isFullscreen ? MinimizeIcon : ExpandIcon;
return (
Expand Down

0 comments on commit 2146b66

Please sign in to comment.