diff --git a/src/components/ui/data-table-pagination.tsx b/src/components/ui/data-table-pagination.tsx index 33fa302..6fa0c3b 100644 --- a/src/components/ui/data-table-pagination.tsx +++ b/src/components/ui/data-table-pagination.tsx @@ -1,4 +1,4 @@ -import { type Table } from '@tanstack/react-table'; +import { type Table, PaginationState } from '@tanstack/react-table'; import { Button } from './button'; import { ArrowLeft, @@ -6,14 +6,24 @@ import { ArrowRight, ArrowRightFromLine, } from 'lucide-react'; - +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from '@/components/ui/select'; interface DataTablePaginationProps { table: Table; pageSizeOptions?: number[]; + setPagination: ( + updater: PaginationState | ((prev: PaginationState) => PaginationState) + ) => void; } function DataTablePagination({ table, pageSizeOptions = [10, 20, 30, 40, 50], + setPagination, }: DataTablePaginationProps) { return (
@@ -61,19 +71,30 @@ function DataTablePagination({ > - { + console.log('size', value); + // table.setPageSize(Number(value)); + const newPageSize = Number(value); + setPagination((prev) => ({ + ...prev, + pageSize: newPageSize, + pageIndex: 0, + })); }} > - {pageSizeOptions.map((size) => ( - - ))} - + + + + + {pageSizeOptions.map((size) => ( + + {size} + + ))} + +
diff --git a/src/components/ui/data-table.tsx b/src/components/ui/data-table.tsx index bc99aa9..97bca4c 100644 --- a/src/components/ui/data-table.tsx +++ b/src/components/ui/data-table.tsx @@ -2,7 +2,7 @@ import { ColumnDef, flexRender, getCoreRowModel, - getPaginationRowModel, + // getPaginationRowModel, useReactTable, PaginationState, } from '@tanstack/react-table'; @@ -18,7 +18,7 @@ import DataTablePagination from './data-table-pagination'; interface DataTableProps { columns: ColumnDef[]; data: TData[]; - // pageCount: number; + rowCount: number; pagination: PaginationState; setPagination: ( updater: PaginationState | ((prev: PaginationState) => PaginationState) @@ -28,20 +28,18 @@ interface DataTableProps { function DataTable({ columns, data, - // pageCount, + rowCount, pagination, setPagination, }: DataTableProps) { const table = useReactTable({ data, columns, - getCoreRowModel: getCoreRowModel(), - // pageCount: -1, + rowCount, state: { pagination }, - onPaginationChange: (updater) => { - setPagination((prev) => ({ ...prev, ...updater })); - }, - getPaginationRowModel: getPaginationRowModel(), + getCoreRowModel: getCoreRowModel(), + onPaginationChange: setPagination, + // getPaginationRowModel: getPaginationRowModel(), manualPagination: true, }); return ( @@ -49,7 +47,7 @@ function DataTable({ {table.getHeaderGroups().map((headerGroup) => ( - + {headerGroup.headers.map((header) => { return ( @@ -70,6 +68,7 @@ function DataTable({ {row.getVisibleCells().map((cell) => ( @@ -80,7 +79,7 @@ function DataTable({ ))}
- + ); } diff --git a/src/pages/JobDetail.tsx b/src/pages/JobDetail.tsx new file mode 100644 index 0000000..27fe591 --- /dev/null +++ b/src/pages/JobDetail.tsx @@ -0,0 +1,5 @@ +const JobDetail = () => { + return
JobDetail
; +}; + +export default JobDetail; diff --git a/src/pages/Jobs.tsx b/src/pages/Jobs.tsx index 44dadff..1bf2574 100644 --- a/src/pages/Jobs.tsx +++ b/src/pages/Jobs.tsx @@ -8,16 +8,29 @@ import { Database } from '@/types/supabase'; import { Card } from '@/components/ui/card'; import { ColumnDef } from '@tanstack/react-table'; import DataTable from '@/components/ui/data-table'; +import { Link } from 'react-router-dom'; const columns: ColumnDef[] = [ { accessorKey: 'title', header: 'Title', + cell({ row }) { + return ( + {`${row.original.title}`} + ); + }, }, { accessorKey: 'location', header: 'Location', }, + { + accessorKey: 'closing_date', + header: 'Application Deadline', + }, ]; const Jobs = () => { @@ -30,21 +43,22 @@ const Jobs = () => { pageIndex: 0, pageSize: 10, }); - // const [pageCount, setPageCount] = useState(0); + const [pageCount, setPageCount] = useState(0); useEffect(() => { getJobs(pagination.pageIndex, pagination.pageSize); }, [pagination]); const getJobs = async (pageIndex: number, pageSize: number) => { + setLoading(true); try { - setLoading(true); - const { data } = await supabase + const { data, count } = await supabase .from('jobs') - .select() + .select('*', { count: 'exact' }) .range(pageIndex * pageSize, (pageIndex + 1) * pageSize - 1); - console.log('jobs', data); + console.log('jobs', data, count); setJobs(data || []); + setPageCount(count || 0); } catch (error) { if (error instanceof Error) { console.log(error); @@ -67,13 +81,15 @@ const Jobs = () => {

Jobs

- + {!displayUnavailable && !displayLoading && !displayError && ( + + )} {displayUnavailable &&

Jobs not available

} {displayLoading && } {displayError &&

{errorMsg}

} diff --git a/src/routes.tsx b/src/routes.tsx index 1c8c8e7..27f98e8 100644 --- a/src/routes.tsx +++ b/src/routes.tsx @@ -2,6 +2,7 @@ import { Suspense, lazy } from 'react'; import type { RouteObject } from 'react-router-dom'; import AuthGuard from './components/guards/AuthGuard'; +import { Outlet } from 'react-router-dom'; // eslint-disable-next-line @typescript-eslint/no-explicit-any const Loadable = (Component: any) => (props: JSX.IntrinsicAttributes) => ( @@ -15,6 +16,7 @@ const Home = Loadable(lazy(() => import('./pages/Home'))); const Login = Loadable(lazy(() => import('./pages/Login'))); const Register = Loadable(lazy(() => import('./pages/Register'))); const Jobs = Loadable(lazy(() => import('./pages/Jobs'))); +const JobDetail = Loadable(lazy(() => import('./pages/JobDetail'))); const DashboardLayout = Loadable(lazy(() => import('./pages/DashboardLayout'))); @@ -26,7 +28,17 @@ const routes: RouteObject[] = [ }, { path: 'jobs', - element: , + element: , + children: [ + { + index: true, + element: , + }, + { + path: ':id', + element: , + }, + ], }, //TODO: Add Guest Guard