mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-20 14:34:05 +01:00
feat: add pagination
This commit is contained in:
parent
aced63fbe6
commit
6afa6443c6
@ -1,11 +1,11 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Clock3Icon, UserIcon, UsersIcon } from "lucide-react";
|
import { Clock3Icon, UserIcon, UsersIcon } from "lucide-react";
|
||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { ProjectCard } from "@/components/projectCard";
|
import { ProjectCard } from "@/components/projectCard";
|
||||||
import { getAllTagsQuery, getALlFundedStatusQuery, getAllBusinessTypeQuery } from "@/lib/data/dropdownQuery";
|
import { getALlFundedStatusQuery, getAllBusinessTypeQuery } from "@/lib/data/dropdownQuery";
|
||||||
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
|
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
|
||||||
import { useQuery } from "@supabase-cache-helpers/postgrest-react-query";
|
import { useQuery } from "@supabase-cache-helpers/postgrest-react-query";
|
||||||
import { searchProjectsQuery, FilterParams, FilterProjectQueryParams } from "@/lib/data/projectQuery";
|
import { searchProjectsQuery, FilterParams, FilterProjectQueryParams } from "@/lib/data/projectQuery";
|
||||||
@ -13,7 +13,29 @@ import { Input } from "@/components/ui/input";
|
|||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
|
||||||
const ProjectSection = ({ filteredProjects }) => {
|
interface Project {
|
||||||
|
project_id: string;
|
||||||
|
project_name: string;
|
||||||
|
published_time: string;
|
||||||
|
project_short_description: string;
|
||||||
|
card_image_url: string;
|
||||||
|
project_status: {
|
||||||
|
value: string;
|
||||||
|
};
|
||||||
|
min_investment: number;
|
||||||
|
total_investment: number;
|
||||||
|
target_investment: number;
|
||||||
|
investment_deadline: string;
|
||||||
|
tags: {
|
||||||
|
tag_name: string;
|
||||||
|
}[];
|
||||||
|
business_type: {
|
||||||
|
value: string;
|
||||||
|
};
|
||||||
|
business_location: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ProjectSection = ({ filteredProjects }: { filteredProjects: Project[] }) => {
|
||||||
interface Tags {
|
interface Tags {
|
||||||
tag_name: string;
|
tag_name: string;
|
||||||
}
|
}
|
||||||
@ -117,7 +139,7 @@ export default function Deals() {
|
|||||||
const [sortByTimeFilter, setSortByTimeFilter] = useState("all");
|
const [sortByTimeFilter, setSortByTimeFilter] = useState("all");
|
||||||
const [businessTypeFilter, setBusinessTypeFilter] = useState("all");
|
const [businessTypeFilter, setBusinessTypeFilter] = useState("all");
|
||||||
const [tagFilter, setTagFilter] = useState([]);
|
const [tagFilter, setTagFilter] = useState([]);
|
||||||
const [projectStatusFilter, setprojectStatusFilter] = useState("all");
|
const [projectStatusFilter, setProjectStatusFilter] = useState("all");
|
||||||
const [page, setPage] = useState(1);
|
const [page, setPage] = useState(1);
|
||||||
const [pageSize, setPageSize] = useState(4);
|
const [pageSize, setPageSize] = useState(4);
|
||||||
|
|
||||||
@ -139,7 +161,6 @@ export default function Deals() {
|
|||||||
pageSize,
|
pageSize,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { data: tags, isLoading: isLoadingTags, error: tagsLoadingError } = useQuery(getAllTagsQuery(supabase));
|
|
||||||
const {
|
const {
|
||||||
data: projectStatus,
|
data: projectStatus,
|
||||||
isLoading: isLoadingFunded,
|
isLoading: isLoadingFunded,
|
||||||
@ -160,11 +181,20 @@ export default function Deals() {
|
|||||||
const clearAll = () => {
|
const clearAll = () => {
|
||||||
setSearchTerm("");
|
setSearchTerm("");
|
||||||
setTagFilter([]);
|
setTagFilter([]);
|
||||||
setprojectStatusFilter("all");
|
setProjectStatusFilter("all");
|
||||||
setBusinessTypeFilter("all");
|
setBusinessTypeFilter("all");
|
||||||
setSortByTimeFilter("all");
|
setSortByTimeFilter("all");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handlePageSizeChange = (value: number) => {
|
||||||
|
setPageSize(value);
|
||||||
|
setPage(1);
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setSearchTerm(searchTermVisual);
|
||||||
|
}, [searchTermVisual]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container max-w-screen-xl mx-auto px-4">
|
<div className="container max-w-screen-xl mx-auto px-4">
|
||||||
<div className="h-auto mt-10">
|
<div className="h-auto mt-10">
|
||||||
@ -175,8 +205,7 @@ export default function Deals() {
|
|||||||
All companies are <u>vetted & pass due diligence.</u>
|
All companies are <u>vetted & pass due diligence.</u>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{/* {JSON.stringify(projects, null, 4)} */}
|
{/* Search Input and Filters */}
|
||||||
|
|
||||||
<div className="flex mt-10 gap-3">
|
<div className="flex mt-10 gap-3">
|
||||||
<Input
|
<Input
|
||||||
type="text"
|
type="text"
|
||||||
@ -205,7 +234,7 @@ export default function Deals() {
|
|||||||
</Select>
|
</Select>
|
||||||
|
|
||||||
{/* Business Type Filter */}
|
{/* Business Type Filter */}
|
||||||
<Select onValueChange={(value) => setBusinessTypeFilter}>
|
<Select onValueChange={(value) => setBusinessTypeFilter(value)}>
|
||||||
<SelectTrigger className="w-full sm:w-[180px]">
|
<SelectTrigger className="w-full sm:w-[180px]">
|
||||||
<UsersIcon className="ml-2" />
|
<UsersIcon className="ml-2" />
|
||||||
<SelectValue placeholder="Business Type" />
|
<SelectValue placeholder="Business Type" />
|
||||||
@ -234,7 +263,7 @@ export default function Deals() {
|
|||||||
</Select>
|
</Select>
|
||||||
|
|
||||||
{/* Project Status Filter */}
|
{/* Project Status Filter */}
|
||||||
<Select onValueChange={(key) => setprojectStatusFilter(key)}>
|
<Select onValueChange={(key) => setProjectStatusFilter(key)}>
|
||||||
<SelectTrigger className="w-full sm:w-[180px]">
|
<SelectTrigger className="w-full sm:w-[180px]">
|
||||||
<UserIcon className="ml-2" />
|
<UserIcon className="ml-2" />
|
||||||
<SelectValue placeholder="Project Status" />
|
<SelectValue placeholder="Project Status" />
|
||||||
@ -262,11 +291,54 @@ export default function Deals() {
|
|||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Active Filters */}
|
||||||
<ShowFilter filterParams={filterParams} clearAll={clearAll} />
|
<ShowFilter filterParams={filterParams} clearAll={clearAll} />
|
||||||
<Separator className="mt-10" />
|
<Separator className="mt-10" />
|
||||||
|
|
||||||
{/* Project Cards Section */}
|
{/* Project Cards Section */}
|
||||||
|
{isLoadingProjects ? (
|
||||||
|
<div>Loading...</div>
|
||||||
|
) : projectsLoadingError ? (
|
||||||
|
<div>Error loading projects.</div>
|
||||||
|
) : projects ? (
|
||||||
<ProjectSection filteredProjects={projects} />
|
<ProjectSection filteredProjects={projects} />
|
||||||
|
) : (
|
||||||
|
<div>No projects found!</div>
|
||||||
|
)}
|
||||||
|
{/* Pagination Controls */}
|
||||||
|
<div className="mt-6 flex items-center justify-between">
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => setPage((prevPage) => Math.max(prevPage - 1, 1))}
|
||||||
|
disabled={page === 1}
|
||||||
|
>
|
||||||
|
Previous
|
||||||
|
</Button>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span>Page Size:</span>
|
||||||
|
<Select onValueChange={(value) => handlePageSizeChange(Number(value))}>
|
||||||
|
<SelectTrigger className="w-[100px]">
|
||||||
|
<SelectValue placeholder={`${pageSize}`} />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
<SelectItem value="4">4</SelectItem>
|
||||||
|
<SelectItem value="8">8</SelectItem>
|
||||||
|
<SelectItem value="12">12</SelectItem>
|
||||||
|
<SelectItem value="16">16</SelectItem>
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => setPage((prevPage) => prevPage + 1)}
|
||||||
|
disabled={projects! && projects.length < pageSize}
|
||||||
|
>
|
||||||
|
Next
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user