-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Table cards now paginate independently (#80)
- Loading branch information
1 parent
6ce3675
commit 848569e
Showing
14 changed files
with
735 additions
and
326 deletions.
There are no files selected for viewing
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 { useEffect } from "react"; | ||
import TableCard from "~/components/TableCard"; | ||
|
||
import { Card } from "./ui/card"; | ||
import PaginationButtons from "./PaginationButtons"; | ||
|
||
const ReferrerCard = ({ | ||
siteId, | ||
interval, | ||
dataFetcher, | ||
columnHeaders, | ||
loaderUrl, | ||
}: { | ||
siteId: string; | ||
interval: string; | ||
dataFetcher: any; // ignore type for now | ||
columnHeaders: string[]; | ||
loaderUrl: string; | ||
}) => { | ||
const countsByProperty = dataFetcher.data?.countsByProperty || []; | ||
const page = dataFetcher.data?.page || 1; | ||
|
||
useEffect(() => { | ||
if (dataFetcher.state === "idle") { | ||
dataFetcher.load( | ||
`${loaderUrl}?site=${siteId}&interval=${interval}`, | ||
); | ||
} | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (dataFetcher.state === "idle") { | ||
dataFetcher.load( | ||
`${loaderUrl}?site=${siteId}&interval=${interval}`, | ||
); | ||
} | ||
}, [siteId, interval]); | ||
|
||
function handlePagination(page: number) { | ||
dataFetcher.load( | ||
`${loaderUrl}?site=${siteId}&interval=${interval}&page=${page}`, | ||
); | ||
} | ||
|
||
const hasMore = countsByProperty.length === 10; | ||
return ( | ||
<Card className={dataFetcher.state === "loading" ? "opacity-60" : ""}> | ||
{countsByProperty ? ( | ||
<div className="grid grid-rows-[auto,40px] h-full"> | ||
<TableCard | ||
countByProperty={countsByProperty} | ||
columnHeaders={columnHeaders} | ||
/> | ||
<PaginationButtons | ||
page={page} | ||
hasMore={hasMore} | ||
handlePagination={handlePagination} | ||
/> | ||
</div> | ||
) : null} | ||
</Card> | ||
); | ||
}; | ||
|
||
export default ReferrerCard; |
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,47 @@ | ||
import React from "react"; | ||
|
||
import { ArrowLeft, ArrowRight } from "lucide-react"; | ||
|
||
interface PaginationButtonsProps { | ||
page: number; | ||
hasMore: boolean; | ||
handlePagination: (page: number) => void; | ||
} | ||
|
||
const PaginationButtons: React.FC<PaginationButtonsProps> = ({ | ||
page, | ||
hasMore, | ||
handlePagination, | ||
}) => { | ||
return ( | ||
<div className="p-2 pr-0 grid grid-cols-[auto,2rem,2rem] text-right"> | ||
<div></div> | ||
<button | ||
onClick={() => { | ||
if (page > 1) handlePagination(page - 1); | ||
}} | ||
className={ | ||
page > 1 | ||
? `text-primary hover:cursor-pointer` | ||
: `text-orange-300` | ||
} | ||
> | ||
<ArrowLeft /> | ||
</button> | ||
<button | ||
onClick={() => { | ||
if (hasMore) handlePagination(page + 1); | ||
}} | ||
className={ | ||
hasMore | ||
? "text-primary hover:cursor-pointer" | ||
: "text-orange-300" | ||
} | ||
> | ||
<ArrowRight /> | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PaginationButtons; |
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
Oops, something went wrong.