Skip to content

Commit

Permalink
Decrement page if empty on Cardlist
Browse files Browse the repository at this point in the history
If you removed an item from the cardlist so that the page is empty afterwards then, and only then, change the page

Closes PelicanPlatform#1473
  • Loading branch information
CannonLock committed Oct 22, 2024
1 parent 9a38446 commit cf051bb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions web_ui/frontend/components/CardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ export function CardList<T>({ data, Card, cardProps }: CardListProps<T>) {
const PAGE_SIZE = 5;
const [page, setPage] = useState<number>(1);

// Reset the page on data length change
// Minus the page if the data length changes
useEffect(() => {
setPage(1);
if (data?.length && page > Math.ceil(data.length / PAGE_SIZE)) {
setPage(Math.max(1, Math.ceil(data.length / PAGE_SIZE)));
}
}, [data?.length]);

const count = useMemo(() => {
Expand Down

0 comments on commit cf051bb

Please sign in to comment.