mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-20 06:24:06 +01:00
refactor: extract supabase query + use projectCard instead of extendableCard
This commit is contained in:
parent
ca5764fb24
commit
690c44bd7d
@ -3,7 +3,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Clock3Icon, MessageSquareIcon, UserIcon, UsersIcon } from "lucide-react";
|
import { Clock3Icon, MessageSquareIcon, UserIcon, UsersIcon } from "lucide-react";
|
||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { ExtendableCard } from "@/components/extendableCard";
|
import { ProjectCard } from "@/components/projectCard";
|
||||||
|
|
||||||
export default function Deals() {
|
export default function Deals() {
|
||||||
const [postAtFilter, setPostAtFilter] = useState("");
|
const [postAtFilter, setPostAtFilter] = useState("");
|
||||||
@ -111,7 +111,7 @@ export default function Deals() {
|
|||||||
{/* Block for all the deals */}
|
{/* Block for all the deals */}
|
||||||
<div className="mt-10 grid grid-cols-3 gap-4">
|
<div className="mt-10 grid grid-cols-3 gap-4">
|
||||||
{filteredData.map((item, index) => (
|
{filteredData.map((item, index) => (
|
||||||
<ExtendableCard
|
<ProjectCard
|
||||||
key={index}
|
key={index}
|
||||||
name={item.name}
|
name={item.name}
|
||||||
description={item.description}
|
description={item.description}
|
||||||
|
|||||||
@ -1,71 +1,25 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useSearchParams } from "next/navigation";
|
import { useSearchParams } from "next/navigation";
|
||||||
import { SupabaseClient } from "@supabase/supabase-js";
|
|
||||||
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
|
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
|
||||||
import { dehydrate, HydrationBoundary, QueryClient } from "@tanstack/react-query";
|
|
||||||
import { useQuery } from "@supabase-cache-helpers/postgrest-react-query";
|
import { useQuery } from "@supabase-cache-helpers/postgrest-react-query";
|
||||||
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
|
||||||
import { ExtendableCard } from "@/components/extendableCard";
|
import { ProjectCard } from "@/components/projectCard";
|
||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
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 {
|
interface ProjectInvestmentDetail extends Tables<"ProjectInvestmentDetail"> {}
|
||||||
minInvestment: number;
|
|
||||||
totalInvestment: number;
|
|
||||||
targetInvestment: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Project {
|
interface Project extends Tables<"Project"> {
|
||||||
id: string;
|
|
||||||
projectName: string;
|
|
||||||
businessId: string;
|
|
||||||
investmentCount: number;
|
|
||||||
projectShortDescription: string;
|
|
||||||
publishedTime: string;
|
|
||||||
ProjectInvestmentDetail: ProjectInvestmentDetail[];
|
ProjectInvestmentDetail: ProjectInvestmentDetail[];
|
||||||
tags: string[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Business {
|
interface Business extends Tables<"Business"> {
|
||||||
id: string;
|
|
||||||
businessName: string;
|
|
||||||
joinedDate: string;
|
|
||||||
Projects: Project[];
|
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() {
|
export default function Find() {
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const query = searchParams.get("query");
|
const query = searchParams.get("query");
|
||||||
@ -132,22 +86,6 @@ export default function Find() {
|
|||||||
<ul>
|
<ul>
|
||||||
{results.map((business) => (
|
{results.map((business) => (
|
||||||
<li key={business.id}>
|
<li key={business.id}>
|
||||||
{/* <h2>{business.businessName}</h2>
|
|
||||||
<p>Joined Date: {new Date(business.joinedDate).toLocaleDateString()}</p>
|
|
||||||
{business.Projects.map((project) => (
|
|
||||||
<ExtendableCard
|
|
||||||
key={project.id}
|
|
||||||
name={project.projectName}
|
|
||||||
description={project.projectName}
|
|
||||||
joinDate={project.projectName}
|
|
||||||
location={"Bangkok"}
|
|
||||||
minInvestment={project.ProjectInvestmentDetail[0]?.minInvestment}
|
|
||||||
totalInvestor={project.ProjectInvestmentDetail[0]?.totalInvestment}
|
|
||||||
totalRaised={project.ProjectInvestmentDetail[0]?.targetInvestment}
|
|
||||||
tags={null}
|
|
||||||
/>
|
|
||||||
))} */}
|
|
||||||
|
|
||||||
<Card className="w-full">
|
<Card className="w-full">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>{business.businessName}</CardTitle>
|
<CardTitle>{business.businessName}</CardTitle>
|
||||||
@ -155,7 +93,7 @@ export default function Find() {
|
|||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
{business.Projects.map((project) => (
|
{business.Projects.map((project) => (
|
||||||
<ExtendableCard
|
<ProjectCard
|
||||||
key={project.id}
|
key={project.id}
|
||||||
name={project.projectName}
|
name={project.projectName}
|
||||||
description={project.projectName}
|
description={project.projectName}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { Button } from "@/components/ui/button";
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { ExtendableCard } from "@/components/extendableCard";
|
import { ProjectCard } from "@/components/projectCard";
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
return (
|
return (
|
||||||
@ -83,7 +83,7 @@ export default function Home() {
|
|||||||
</span>
|
</span>
|
||||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4">
|
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4">
|
||||||
<Link href={"/overview"}>
|
<Link href={"/overview"}>
|
||||||
<ExtendableCard
|
<ProjectCard
|
||||||
name={"NVDA"}
|
name={"NVDA"}
|
||||||
description={"Founded in 1993, NVIDIA is a key innovator of computer graphics and AI technology"}
|
description={"Founded in 1993, NVIDIA is a key innovator of computer graphics and AI technology"}
|
||||||
joinDate={"December 2021"}
|
joinDate={"December 2021"}
|
||||||
@ -94,7 +94,7 @@ export default function Home() {
|
|||||||
totalRaised={9000000}
|
totalRaised={9000000}
|
||||||
/>
|
/>
|
||||||
</Link>
|
</Link>
|
||||||
<ExtendableCard
|
<ProjectCard
|
||||||
name={"Apple Inc."}
|
name={"Apple Inc."}
|
||||||
description={
|
description={
|
||||||
"Founded in 1976, Apple Inc. is a leading innovator in consumer electronics, software, and online services, known for products like the iPhone, MacBook, and the App Store."
|
"Founded in 1976, Apple Inc. is a leading innovator in consumer electronics, software, and online services, known for products like the iPhone, MacBook, and the App Store."
|
||||||
@ -106,7 +106,7 @@ export default function Home() {
|
|||||||
totalInvestor={58400}
|
totalInvestor={58400}
|
||||||
totalRaised={9000000}
|
totalRaised={9000000}
|
||||||
/>
|
/>
|
||||||
<ExtendableCard
|
<ProjectCard
|
||||||
name={"Google LLC"}
|
name={"Google LLC"}
|
||||||
description={
|
description={
|
||||||
"Founded in 1998, Google LLC specializes in internet-related services and products, including search engines, online advertising, cloud computing, and the Android operating system."
|
"Founded in 1998, Google LLC specializes in internet-related services and products, including search engines, online advertising, cloud computing, and the Android operating system."
|
||||||
@ -118,7 +118,7 @@ export default function Home() {
|
|||||||
totalInvestor={5000}
|
totalInvestor={5000}
|
||||||
totalRaised={1500000000}
|
totalRaised={1500000000}
|
||||||
/>
|
/>
|
||||||
<ExtendableCard
|
<ProjectCard
|
||||||
name={"Microsoft Corporation"}
|
name={"Microsoft Corporation"}
|
||||||
description={"Microsoft Corporation is a multinational technology company."}
|
description={"Microsoft Corporation is a multinational technology company."}
|
||||||
joinDate={"January 2018"}
|
joinDate={"January 2018"}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ interface XMap {
|
|||||||
[tag: string]: string;
|
[tag: string]: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ExtendableCardProps {
|
interface ProjectCardProps {
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
joinDate: string;
|
joinDate: string;
|
||||||
@ -21,7 +21,7 @@ interface ExtendableCardProps {
|
|||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ExtendableCard(props: ExtendableCardProps) {
|
export function ProjectCard(props: ProjectCardProps) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
35
src/lib/data/query.ts
Normal file
35
src/lib/data/query.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { SupabaseClient } from "@supabase/supabase-js";
|
||||||
|
|
||||||
|
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 { getBusinesses, getProjects, getTags, getInvestmentCounts };
|
||||||
Loading…
Reference in New Issue
Block a user