diff --git a/src/app/(investment)/deals/[id]/page.tsx b/src/app/(investment)/deals/[id]/page.tsx index 08a1430..73ef4be 100644 --- a/src/app/(investment)/deals/[id]/page.tsx +++ b/src/app/(investment)/deals/[id]/page.tsx @@ -5,13 +5,12 @@ 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"; @@ -19,6 +18,7 @@ import { redirect } from "next/navigation"; import { isOwnerOfProject } from "./query"; import { UpdateTab } from "./UpdateTab"; 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" }]; @@ -104,35 +103,8 @@ export default async function ProjectDealPage({ params }: { params: { id: number
{/* image carousel */} - - +
); } diff --git a/src/app/portfolio/[uid]/page.tsx b/src/app/portfolio/[uid]/page.tsx index 8356d48..b154941 100644 --- a/src/app/portfolio/[uid]/page.tsx +++ b/src/app/portfolio/[uid]/page.tsx @@ -52,7 +52,6 @@ export default async function Portfolio({ params }: { params: { uid: string } }) ); } const username = localUser ? localUser.user.user_metadata.name : "Anonymous"; - // console.log(username) const overAllData = deals ? overAllGraphData(deals) : []; const fourYearData = deals ? fourYearGraphData(deals) : []; const dayOfWeekData = deals ? dayOftheWeekData(deals) : []; @@ -66,31 +65,13 @@ export default async function Portfolio({ params }: { params: { uid: string } }) ) : []; const totalInvestment = deals ? getTotalInvestment(deals) : 0; - // console.log(latestDeals); - const tagCount = countTags(tags); - // console.log(investedBusinessIds); const businessType = deals ? await Promise.all(deals.map(async (item) => await getBusinessTypeName(supabase, item.project_id))) : []; const countedBusinessType = countValues(businessType.filter((item) => item !== null)); - // console.log(countedBusinessType); - - // console.log(tagCount); return (
- {/* {JSON.stringify(params.uid)} */} - {/* {JSON.stringify(tagCount)} */} - {/* {JSON.stringify(deals)} */} - {/* {JSON.stringify(dayOfWeekData)} */} - {/* {JSON.stringify(overAllGraphData)} */} - {/* {JSON.stringify(threeYearGraphData)} */} - {/* {JSON.stringify(uniqueProjectIds)} */} - {/*
-

Total Invest :

-
{totalInvest}
-
*/} - {/* */}

Welcome to your Portfolio, {username}!

diff --git a/src/app/portfolio/[uid]/query.ts b/src/app/portfolio/[uid]/query.ts index 151d0eb..aac9153 100644 --- a/src/app/portfolio/[uid]/query.ts +++ b/src/app/portfolio/[uid]/query.ts @@ -26,11 +26,11 @@ function getTotalInvestment(deals: { deal_amount: number }[]) { } async function getLatestInvestment( supabase: SupabaseClient, - deals: { project_id: number; deal_amount: number; created_time: Date }[] + deals: { project_id: number; deal_amount: number; created_time: Date;}[] ) { const llist = []; const count = 8; - + // select project name from the given id for (let i = deals.length - 1; i >= 0 && llist.length < count; --i) { let { data: project, error } = await supabase.from("project").select("project_name").eq("id", deals[i].project_id); if (error) { @@ -38,6 +38,7 @@ async function getLatestInvestment( } let url = fetchLogoURL(supabase, deals[i].project_id); llist.push({ + projectId: deals[i].project_id, name: project?.[0]?.project_name, amount: deals[i].deal_amount, date: new Date(deals[i].created_time), @@ -104,7 +105,7 @@ async function getBusinessTypeName(supabase: SupabaseClient, projectId: number) } // only use deal that were made at most year ago -interface Deal { +export interface Deal { created_time: string | number | Date; deal_amount: any; } 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) => ( + + {`Carousel + + )), + [images] + ); + + const thumbnailImages = useMemo( + () => + images.map((image, index) => ( + handleClick(index)}> + {`Carousel + + )), + [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; diff --git a/src/components/projectCard.tsx b/src/components/projectCard.tsx index ded4889..86de0f5 100644 --- a/src/components/projectCard.tsx +++ b/src/components/projectCard.tsx @@ -71,15 +71,19 @@ export function ProjectCard(props: ProjectCardProps) { {props.location}
- {props.tags && Array.isArray(props.tags) ? ( - props.tags.map((tag) => ( - - {tag} - - )) - ) : ( - No tags available - )} + {props.tags?.length !== 0 && Array.isArray(props.tags) + ? props.tags + .filter((tag) => tag && tag.trim() !== "") // Filters out null or blank tags + .map((tag) => ( + + {tag} + + )) + : null}
diff --git a/src/components/recent-funds.tsx b/src/components/recent-funds.tsx index 3707d2d..dd47e91 100644 --- a/src/components/recent-funds.tsx +++ b/src/components/recent-funds.tsx @@ -1,4 +1,5 @@ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; +import Link from "next/link"; export type RecentDealData = { created_time: Date; @@ -6,29 +7,127 @@ export type RecentDealData = { investor_id: string; username: string; logo_url?: string; + status?: string; // email: string; }; interface RecentFundsProps { - data?: { name?: string; amount?: number; avatar?: string; date?: Date; logo_url?: string }[]; + data?: { name?: string; amount?: number; avatar?: string; date?: Date; logo_url?: string; status?: string; profile_url?: string }[]; } export function RecentFunds(props: RecentFundsProps) { + const content = ( +
+ +
+ ) return (
{(props?.data || []).map((deal, index) => ( -
- - - {(deal.name ?? "").slice(0, 2)} - -
-

{deal.name}

-

{deal?.date?.toLocaleDateString()}

-
-
+${deal.amount}
+
+ {deal.profile_url ? ( + + + + {(deal.name ?? "").slice(0, 2)} + +
+

{deal.name}

+

{deal?.date?.toLocaleDateString()}

+ {deal.status && ( +
+ + + + +

+ {deal?.status} +

+
+ )} +
+
+${deal.amount}
+ + ) : ( +
+ + + {(deal.name ?? "").slice(0, 2)} + +
+

{deal.name}

+

{deal?.date?.toLocaleDateString()}

+ {deal.status && ( +
+ + + + +

+ {deal?.status} +

+
+ )} +
+
+${deal.amount}
+
+ )}
))}
); + } diff --git a/src/lib/data/investmentQuery.ts b/src/lib/data/investmentQuery.ts index da17b3b..df9a944 100644 --- a/src/lib/data/investmentQuery.ts +++ b/src/lib/data/investmentQuery.ts @@ -10,6 +10,29 @@ export const getInvestmentCountsByProjectsIds = (client: SupabaseClient, project .in("project_id", projectIds); }; +export const getInvestmentByProjectsIds = (client: SupabaseClient, projectIds: string[]) => { + return client + .from("investment_deal") + .select( + ` + id, + ...deal_status_id( + deal_status:value + ), + project_id, + deal_amount, + created_time, + ...profiles ( + investor_id:id, + username, + avatar_url + ) + ` + ) + .in("project_id", projectIds) + .order("created_time", { ascending: false }); +}; + export const getInvestmentByUserId = (client: SupabaseClient, userId: string) => { return client .from("investment_deal")