diff --git a/src/app/(investment)/deals/[id]/page.tsx b/src/app/(investment)/deals/[id]/page.tsx
index f6d8280..8060968 100644
--- a/src/app/(investment)/deals/[id]/page.tsx
+++ b/src/app/(investment)/deals/[id]/page.tsx
@@ -5,19 +5,19 @@ import ReactMarkdown from "react-markdown";
import * as Tabs from "@radix-ui/react-tabs";
import { Button } from "@/components/ui/button";
-import { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious } from "@/components/ui/carousel";
import { Card, CardContent, CardHeader, CardTitle, CardDescription, CardFooter } from "@/components/ui/card";
import { Progress } from "@/components/ui/progress";
import { Separator } from "@/components/ui/separator";
import { createSupabaseClient } from "@/lib/supabase/serverComponentClient";
import FollowShareButtons from "./followShareButton";
-import { DisplayFullImage } from "./displayImage";
+
import { getProjectData } from "@/lib/data/projectQuery";
import { getDealList } from "@/app/api/dealApi";
import { sumByKey, toPercentage } from "@/lib/utils";
import { redirect } from "next/navigation";
import { isOwnerOfProject } from "./query";
import remarkGfm from "remark-gfm";
+import Gallery from "@/components/carousel";
const PHOTO_MATERIAL_ID = 2;
@@ -75,7 +75,6 @@ export default async function ProjectDealPage({ params }: { params: { id: number
? projectMaterial.flatMap((item) =>
(item.material_url || ["/boiler1.jpg"]).map((url: string) => ({
src: url,
- alt: "Image",
}))
)
: [{ src: "/boiler1.jpg", alt: "Default Boiler Image" }];
@@ -106,35 +105,8 @@ export default async function ProjectDealPage({ params }: { params: { id: number
{/* image carousel */}
-
- {/* first carousel */}
-
-
- {carouselData.map((item, index) => (
-
-
-
- ))}
-
-
-
-
- {/* second carousel */}
-
-
- {carouselData.map((item, index) => (
-
-
-
- ))}
-
-
+
+
diff --git a/src/components/carousel.tsx b/src/components/carousel.tsx
new file mode 100644
index 0000000..5e1386b
--- /dev/null
+++ b/src/components/carousel.tsx
@@ -0,0 +1,88 @@
+"use client";
+import { useEffect, useState, useMemo } from "react";
+import { Carousel, CarouselContent, CarouselItem, type CarouselApi } from "./ui/carousel";
+import Image from "next/image";
+
+interface GalleryProps {
+ images: { src: string }[];
+}
+
+const Gallery = ({ images }: GalleryProps) => {
+ const [mainApi, setMainApi] = useState();
+ const [thumbnailApi, setThumbnailApi] = useState();
+ const [current, setCurrent] = useState(0);
+
+ const mainImage = useMemo(
+ () =>
+ images.map((image, index) => (
+
+
+
+ )),
+ [images]
+ );
+
+ const thumbnailImages = useMemo(
+ () =>
+ images.map((image, index) => (
+ handleClick(index)}>
+
+
+ )),
+ [images, current]
+ );
+
+ useEffect(() => {
+ if (!mainApi || !thumbnailApi) {
+ return;
+ }
+
+ const handleTopSelect = () => {
+ const selected = mainApi.selectedScrollSnap();
+ setCurrent(selected);
+ thumbnailApi.scrollTo(selected);
+ };
+
+ const handleBottomSelect = () => {
+ const selected = thumbnailApi.selectedScrollSnap();
+ setCurrent(selected);
+ mainApi.scrollTo(selected);
+ };
+
+ mainApi.on("select", handleTopSelect);
+ thumbnailApi.on("select", handleBottomSelect);
+
+ return () => {
+ mainApi.off("select", handleTopSelect);
+ thumbnailApi.off("select", handleBottomSelect);
+ };
+ }, [mainApi, thumbnailApi]);
+
+ const handleClick = (index: number) => {
+ if (!mainApi || !thumbnailApi) {
+ return;
+ }
+ thumbnailApi.scrollTo(index);
+ mainApi.scrollTo(index);
+ setCurrent(index);
+ };
+
+ return (
+
+
+ {mainImage}
+
+
+ {thumbnailImages}
+
+
+ );
+};
+
+export default Gallery;