mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-20 14:34:05 +01:00
refactor: query top project with projetCard view
This commit is contained in:
parent
a0e25d0268
commit
6ca933c47c
@ -8,23 +8,10 @@ import { getTopProjects } from "@/lib/data/projectQuery";
|
|||||||
import { createSupabaseClient } from "@/lib/supabase/serverComponentClient";
|
import { createSupabaseClient } from "@/lib/supabase/serverComponentClient";
|
||||||
import { Suspense } from "react";
|
import { Suspense } from "react";
|
||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
|
import { ProjectCardProps } from "@/types/ProjectCard";
|
||||||
interface Project {
|
|
||||||
id: number;
|
|
||||||
project_name: string;
|
|
||||||
project_short_description: string;
|
|
||||||
card_image_url: string;
|
|
||||||
published_time: string;
|
|
||||||
business: { location: string }[];
|
|
||||||
project_tag: { tag: { id: number; value: string }[] }[];
|
|
||||||
project_investment_detail: {
|
|
||||||
min_investment: number;
|
|
||||||
total_investment: number;
|
|
||||||
}[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface TopProjectsProps {
|
interface TopProjectsProps {
|
||||||
projects: Project[];
|
projects: ProjectCardProps[] | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TopProjects: FC<TopProjectsProps> = ({ projects }) => {
|
const TopProjects: FC<TopProjectsProps> = ({ projects }) => {
|
||||||
@ -34,21 +21,22 @@ const TopProjects: FC<TopProjectsProps> = ({ projects }) => {
|
|||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4">
|
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4">
|
||||||
{projects.map((project) => (
|
{projects.map((project) => (
|
||||||
<Link href={`/deals/${project.id}`} key={project.id}>
|
<div key={project.id}>
|
||||||
|
<Link href={`/deals/${project.id}`}>
|
||||||
<ProjectCard
|
<ProjectCard
|
||||||
name={project.project_name}
|
name={project.project_name}
|
||||||
description={project.project_short_description}
|
description={project.short_description}
|
||||||
imageUri={project.card_image_url}
|
imageUri={project.image_url}
|
||||||
joinDate={new Date(project.published_time).toLocaleDateString()}
|
joinDate={new Date(project.join_date).toLocaleDateString()}
|
||||||
location={project.business[0]?.location || ""}
|
location={project.location}
|
||||||
tags={project.project_tag.flatMap((item: { tag: { id: number; value: string }[] }) =>
|
tags={project.tags}
|
||||||
Array.isArray(item.tag) ? item.tag.map((tag) => tag.value) : []
|
minInvestment={project.min_investment}
|
||||||
)}
|
totalInvestor={project.total_investor}
|
||||||
minInvestment={project.project_investment_detail[0]?.min_investment || 0}
|
totalRaised={project.total_raise}
|
||||||
totalInvestor={0}
|
|
||||||
totalRaised={project.project_investment_detail[0]?.total_investment || 0}
|
|
||||||
/>
|
/>
|
||||||
</Link>
|
</Link>
|
||||||
|
<Separator />
|
||||||
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@ -141,10 +129,12 @@ export default async function Home() {
|
|||||||
<p className="text-md md:text-lg">The deals attracting the most interest right now</p>
|
<p className="text-md md:text-lg">The deals attracting the most interest right now</p>
|
||||||
</span>
|
</span>
|
||||||
{topProjectsError ? (
|
{topProjectsError ? (
|
||||||
<div className="text-red-500">Error fetching projects: {topProjectsError}</div>
|
<div className="text-center text-red-600">
|
||||||
|
<p>Failed to load top projects. Please try again later.</p>
|
||||||
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<Suspense fallback={<ProjectsLoader />}>
|
<Suspense fallback={<ProjectsLoader />}>
|
||||||
<TopProjects projects={topProjectsData || []} />
|
<TopProjects projects={topProjectsData} />
|
||||||
</Suspense>
|
</Suspense>
|
||||||
)}
|
)}
|
||||||
<div className="self-center py-5 scale-75 md:scale-100">
|
<div className="self-center py-5 scale-75 md:scale-100">
|
||||||
|
|||||||
@ -4,43 +4,30 @@ import { ProjectCardProps } from "@/types/ProjectCard";
|
|||||||
async function getTopProjects(client: SupabaseClient, numberOfRecords: number = 4) {
|
async function getTopProjects(client: SupabaseClient, numberOfRecords: number = 4) {
|
||||||
try {
|
try {
|
||||||
const { data, error } = await client
|
const { data, error } = await client
|
||||||
.from("project")
|
.from("project_card")
|
||||||
.select(
|
.select(
|
||||||
`
|
`
|
||||||
id,
|
project_id,
|
||||||
project_name,
|
project_name,
|
||||||
business_id,
|
short_description,
|
||||||
published_time,
|
image_url,
|
||||||
project_short_description,
|
join_date,
|
||||||
card_image_url,
|
location,
|
||||||
project_investment_detail (
|
total_investor,
|
||||||
|
total_raise,
|
||||||
min_investment,
|
min_investment,
|
||||||
total_investment,
|
tags
|
||||||
target_investment,
|
|
||||||
investment_deadline
|
|
||||||
),
|
|
||||||
project_tag (
|
|
||||||
tag (
|
|
||||||
id,
|
|
||||||
value
|
|
||||||
)
|
|
||||||
),
|
|
||||||
business (
|
|
||||||
location
|
|
||||||
)
|
|
||||||
`
|
`
|
||||||
)
|
)
|
||||||
.order("published_time", { ascending: false })
|
.order("total_raise", { ascending: false })
|
||||||
.limit(numberOfRecords);
|
.limit(numberOfRecords);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error("Error fetching top projects:", error.message);
|
|
||||||
return { data: null, error: error.message };
|
return { data: null, error: error.message };
|
||||||
}
|
}
|
||||||
|
|
||||||
return { data, error: null };
|
return { data, error: null };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Unexpected error:", err);
|
|
||||||
return { data: null, error: "An unexpected error occurred." };
|
return { data: null, error: "An unexpected error occurred." };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user