diff --git a/src/app/find/page.tsx b/src/app/find/page.tsx index c3e3672..b6611a9 100644 --- a/src/app/find/page.tsx +++ b/src/app/find/page.tsx @@ -3,27 +3,14 @@ import { useSearchParams } from "next/navigation"; import { createSupabaseClient } from "@/lib/supabase/clientComponentClient"; import { useQuery } from "@supabase-cache-helpers/postgrest-react-query"; -import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; import { ProjectCard } from "@/components/projectCard"; import { Separator } from "@/components/ui/separator"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; -import { getBusinesses, getInvestmentCounts, getProjects, getTags } from "@/lib/data/query"; -import { Tables } from "@/types/database.types"; - -interface ProjectInvestmentDetail extends Tables<"ProjectInvestmentDetail"> {} - -interface Project extends Tables<"Project"> { - ProjectInvestmentDetail: ProjectInvestmentDetail[]; -} - -interface Business extends Tables<"Business"> { - Projects: Project[]; -} +import { getBusinessAndProject } from "@/lib/data/businessQuery"; export default function Find() { const searchParams = useSearchParams(); const query = searchParams.get("query"); - // const query = "neon"; let supabase = createSupabaseClient(); @@ -31,94 +18,62 @@ export default function Find() { data: businesses, isLoading: isLoadingBusinesses, error: businessError, - } = useQuery(getBusinesses(supabase, query)); + } = useQuery(getBusinessAndProject(supabase, query)); - const businessIds = businesses?.map((b) => b.id) || []; - const { - data: projects, - isLoading: isLoadingProjects, - error: projectError, - } = useQuery(getProjects(supabase, businessIds), { - enabled: businessIds.length > 0, - }); - - const projectIds = projects?.map((p) => p.id) || []; - const { - data: tags, - isLoading: isLoadingTags, - error: tagError, - } = useQuery(getTags(supabase, projectIds), { - enabled: projectIds.length > 0, - }); - - const { - data: investmentCounts, - isLoading: isLoadingInvestments, - error: investmentError, - } = useQuery(getInvestmentCounts(supabase, projectIds), { - enabled: projectIds.length > 0, - }); - - // ----- - - const isLoading = isLoadingBusinesses || isLoadingProjects || isLoadingTags || isLoadingInvestments; - const error = businessError || projectError || tagError || investmentError; - - const results: Business[] = - businesses?.map((business) => ({ - ...business, - Projects: - projects - ?.filter((project) => project.businessId === business.id) - .map((project) => ({ - ...project, - tags: tags?.filter((tag) => tag.itemId === project.id).map((tag) => tag.Tag.value) || [], - investmentCount: investmentCounts?.find((ic) => ic.projectId === project.id)?.count || 0, - })) || [], - })) || []; + const isLoading = isLoadingBusinesses; + const error = businessError; if (isLoading) return
Loading...
; if (error) returnError fetching data: {error.message}
; return ( -No results found.
} - {results.length > 0 && ( -No results found.
} + {businesses!.length > 0 && ( +No Projects
+ )} +