-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
157 changed files
with
1,283 additions
and
356 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { CollectionPath } from "@lib/types/db"; | ||
import { getTotalRecords } from "db/firebase/getSize"; | ||
import { useEffect, useState } from "react"; | ||
|
||
export function usePaginatedData<T>( | ||
fetchPage: ( | ||
page: number, | ||
paginationReferences: Map<number, any> | ||
) => Promise<{ data: T[]; paginationInfo: any }>, | ||
type: CollectionPath | ||
) { | ||
const [paginationReferences, setPaginationReferences] = useState< | ||
Map<number, any> | ||
>(new Map()); | ||
const [currPage, setCurrPage] = useState(1); | ||
const [data, setData] = useState<T[]>([]); | ||
const [totalRecords, setTotalRecords] = useState<number>(0); | ||
const [refreshKey, setRefreshKey] = useState<number>(0); | ||
|
||
const fetchTotalRecords = async () => { | ||
try { | ||
const numRecords = await getTotalRecords(type); | ||
if (numRecords) { | ||
setTotalRecords(numRecords); | ||
} | ||
} catch (error) { | ||
console.error("Error fetching records."); | ||
} | ||
}; | ||
|
||
const updatePaginationReferences = async (paginationInfo: any) => { | ||
setPaginationReferences((prev) => { | ||
const newRefs = new Map(prev); | ||
newRefs.set(currPage, paginationInfo); | ||
return newRefs; | ||
}); | ||
}; | ||
|
||
const fetchPageData = async () => { | ||
const newPageData = await fetchPage(currPage, paginationReferences); | ||
setData(newPageData.data); | ||
updatePaginationReferences(newPageData.paginationInfo); | ||
}; | ||
|
||
useEffect(() => { | ||
fetchPageData(); | ||
fetchTotalRecords(); | ||
}, [currPage]); | ||
|
||
useEffect(() => { | ||
setCurrPage(1); | ||
fetchPageData(); | ||
fetchTotalRecords(); | ||
}, [refreshKey]); | ||
|
||
return { | ||
data, | ||
totalRecords, | ||
currPage, | ||
setCurrPage, | ||
onNextPage: () => setCurrPage((prev) => prev + 1), | ||
onPrevPage: () => setCurrPage((prev) => prev - 1), | ||
refresh: () => setRefreshKey((prev) => prev + 1), | ||
}; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from "react"; | ||
import Pagination from "@components/molecules/Pagination/Pagination"; | ||
import CaretakerTable from "@components/tables/CaretakerTable"; | ||
import BabiesTable from "@components/tables/BabiesTable"; | ||
import { BABIES_TAB, CAREGIVERS_TAB } from "@lib/utils/consts"; | ||
|
||
export default function PaginatedTable({ | ||
type, | ||
tableProps, | ||
paginatedProps, | ||
onNextPage, | ||
onPrevPage, | ||
}: any) { | ||
return ( | ||
<div className="flex flex-col gap-4 mb-3 w-[65vw]"> | ||
<div className="overflow-auto h-[70vh]"> | ||
{type == BABIES_TAB ? ( | ||
<BabiesTable props={tableProps} /> | ||
) : type == CAREGIVERS_TAB ? ( | ||
<CaretakerTable props={tableProps} /> | ||
) : ( | ||
<></> | ||
)} | ||
</div> | ||
<div> | ||
<Pagination | ||
totalRecords={paginatedProps.totalRecords} | ||
currPage={paginatedProps.pageNumber} | ||
onNextPage={onNextPage} | ||
onPrevPage={onPrevPage} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.