From 690c44bd7d7c3d3dd9af80321804698a13ad0788 Mon Sep 17 00:00:00 2001 From: sirin Date: Sun, 6 Oct 2024 14:14:44 +0700 Subject: [PATCH] refactor: extract supabase query + use projectCard instead of extendableCard --- src/app/deals/page.tsx | 4 +- src/app/find/page.tsx | 76 ++----------------- src/app/page.tsx | 10 +-- .../{extendableCard.tsx => projectCard.tsx} | 4 +- src/lib/data/query.ts | 35 +++++++++ 5 files changed, 51 insertions(+), 78 deletions(-) rename src/components/{extendableCard.tsx => projectCard.tsx} (97%) create mode 100644 src/lib/data/query.ts diff --git a/src/app/deals/page.tsx b/src/app/deals/page.tsx index 6aff49f..c60cd9a 100644 --- a/src/app/deals/page.tsx +++ b/src/app/deals/page.tsx @@ -3,7 +3,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@ import { useState } from "react"; import { Clock3Icon, MessageSquareIcon, UserIcon, UsersIcon } from "lucide-react"; import { Separator } from "@/components/ui/separator"; -import { ExtendableCard } from "@/components/extendableCard"; +import { ProjectCard } from "@/components/projectCard"; export default function Deals() { const [postAtFilter, setPostAtFilter] = useState(""); @@ -111,7 +111,7 @@ export default function Deals() { {/* Block for all the deals */}
{filteredData.map((item, index) => ( - {} -interface Project { - id: string; - projectName: string; - businessId: string; - investmentCount: number; - projectShortDescription: string; - publishedTime: string; +interface Project extends Tables<"Project"> { ProjectInvestmentDetail: ProjectInvestmentDetail[]; - tags: string[]; } -interface Business { - id: string; - businessName: string; - joinedDate: string; +interface Business extends Tables<"Business"> { Projects: Project[]; } -function getBusinesses(client: SupabaseClient, query: string | null) { - return client.from("Business").select("id, businessName, joinedDate").ilike("businessName", `%${query}%`); -} - -function getProjects(client: SupabaseClient, businessIds: string[]) { - return client - .from("Project") - .select( - ` - id, - projectName, - businessId, - publishedTime, - projectShortDescription, - ProjectInvestmentDetail ( - minInvestment, - totalInvestment, - targetInvestment - ) - ` - ) - .in("businessId", businessIds); -} - -function getTags(client: SupabaseClient, projectIds: string[]) { - return client.from("ItemTag").select("itemId, Tag (value)").in("itemId", projectIds); -} - -function getInvestmentCounts(client: SupabaseClient, projectIds: string[]) { - return client.from("InvestmentDeal").select("*", { count: "exact", head: true }).in("projectId", projectIds); -} - export default function Find() { const searchParams = useSearchParams(); const query = searchParams.get("query"); @@ -132,22 +86,6 @@ export default function Find() {
    {results.map((business) => (
  • - {/*

    {business.businessName}

    -

    Joined Date: {new Date(business.joinedDate).toLocaleDateString()}

    - {business.Projects.map((project) => ( - - ))} */} - {business.businessName} @@ -155,7 +93,7 @@ export default function Find() { {business.Projects.map((project) => ( -
    - - - -