diff --git a/src/app/(investment)/deals/[id]/page.tsx b/src/app/(investment)/deals/[id]/page.tsx
index cdb057c..8cb6b8b 100644
--- a/src/app/(investment)/deals/[id]/page.tsx
+++ b/src/app/(investment)/deals/[id]/page.tsx
@@ -1,8 +1,6 @@
import Image from "next/image";
import Link from "next/link";
-
import ReactMarkdown from "react-markdown";
-
import * as Tabs from "@radix-ui/react-tabs";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle, CardDescription, CardFooter } from "@/components/ui/card";
@@ -10,7 +8,6 @@ import { Progress } from "@/components/ui/progress";
import { Separator } from "@/components/ui/separator";
import { createSupabaseClient } from "@/lib/supabase/serverComponentClient";
import FollowShareButtons from "./followShareButton";
-
import { getProjectData } from "@/lib/data/projectQuery";
import { getDealList } from "@/app/api/dealApi";
import { sumByKey, toPercentage } from "@/lib/utils";
@@ -89,7 +86,7 @@ export default async function ProjectDealPage({ params }: { params: { id: number
{projectData?.project_name}
-
+
{/* end of pack */}
{projectData?.project_short_description}
diff --git a/src/components/carousel.tsx b/src/components/carousel.tsx
index eb994e1..7951303 100644
--- a/src/components/carousel.tsx
+++ b/src/components/carousel.tsx
@@ -1,5 +1,5 @@
"use client";
-import { useEffect, useState, useMemo } from "react";
+import { useEffect, useState, useMemo, useCallback } from "react";
import { Carousel, CarouselContent, CarouselItem, type CarouselApi } from "./ui/carousel";
import Image from "next/image";
@@ -8,15 +8,40 @@ interface GalleryProps {
}
const Gallery = ({ images }: GalleryProps) => {
- const [mainApi, setMainApi] = useState();
- const [thumbnailApi, setThumbnailApi] = useState();
+ const [mainApi, setMainApi] = useState(null);
+ const [thumbnailApi, setThumbnailApi] = useState(null);
const [current, setCurrent] = useState(0);
+ const [isReady, setIsReady] = useState(false);
+
+ const syncCarousels = useCallback(
+ (index: number) => {
+ if (mainApi && thumbnailApi) {
+ setCurrent(index);
+ mainApi.scrollTo(index);
+ thumbnailApi.scrollTo(index);
+ }
+ },
+ [mainApi, thumbnailApi]
+ );
+
+ const handleClick = useCallback(
+ (index: number) => {
+ syncCarousels(index);
+ },
+ [syncCarousels]
+ );
const mainImage = useMemo(
() =>
images.map((image, index) => (
-
+
)),
[images]
@@ -25,61 +50,60 @@ const Gallery = ({ images }: GalleryProps) => {
const thumbnailImages = useMemo(
() =>
images.map((image, index) => (
- handleClick(index)}>
+ handleClick(index)}
+ >
)),
- // eslint-disable-next-line react-hooks/exhaustive-deps
- [images, current]
+ [images, current, handleClick]
);
useEffect(() => {
- if (!mainApi || !thumbnailApi) {
- return;
- }
+ if (!mainApi || !thumbnailApi) return;
+ if (isReady) return;
- const handleTopSelect = () => {
+ const handleMainSelect = () => {
const selected = mainApi.selectedScrollSnap();
- setCurrent(selected);
- thumbnailApi.scrollTo(selected);
+ if (selected !== current) {
+ syncCarousels(selected);
+ }
};
- const handleBottomSelect = () => {
+ const handleThumbnailSelect = () => {
const selected = thumbnailApi.selectedScrollSnap();
- setCurrent(selected);
- mainApi.scrollTo(selected);
+ if (selected !== current) {
+ syncCarousels(selected);
+ }
};
- mainApi.on("select", handleTopSelect);
- thumbnailApi.on("select", handleBottomSelect);
+ mainApi.on("select", handleMainSelect);
+ thumbnailApi.on("select", handleThumbnailSelect);
+
+ syncCarousels(0);
+ setIsReady(true);
return () => {
- mainApi.off("select", handleTopSelect);
- thumbnailApi.off("select", handleBottomSelect);
+ mainApi.off("select", handleMainSelect);
+ thumbnailApi.off("select", handleThumbnailSelect);
};
- }, [mainApi, thumbnailApi]);
-
- const handleClick = (index: number) => {
- if (!mainApi || !thumbnailApi) {
- return;
- }
- thumbnailApi.scrollTo(index);
- mainApi.scrollTo(index);
- setCurrent(index);
- };
+ }, [mainApi, thumbnailApi, current, syncCarousels, isReady]);
return (
-
+
{mainImage}
-
+
{thumbnailImages}
diff --git a/src/components/ui/carousel.tsx b/src/components/ui/carousel.tsx
index 59831f9..2ff1992 100644
--- a/src/components/ui/carousel.tsx
+++ b/src/components/ui/carousel.tsx
@@ -115,14 +115,16 @@ const Carousel = React.forwardRef
+ }}
+ >
+ {...props}
+ >
{children}
@@ -183,7 +185,8 @@ const CarouselPrevious = React.forwardRef
+ {...props}
+ >
Previous slide
@@ -210,7 +213,8 @@ const CarouselNext = React.forwardRef
+ {...props}
+ >
Next slide