Skip to content

Commit 1022781

Browse files
authored
chore: improve pagination UX (#1038)
1 parent c83655c commit 1022781

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Loading } from "../../../../_components/loading";
2+
3+
export default function PackageVersionLoading() {
4+
return <Loading />;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Loading } from "../../../_components/loading";
2+
3+
export default function PackageLoading() {
4+
return <Loading />;
5+
}

app/search/_components/pagination.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { Pagination as NextUIPagination } from "@heroui/react";
44
import { useRouter } from "next/navigation";
5+
import { useTransition } from "react";
56

67
type Props = {
78
query: string;
@@ -12,9 +13,14 @@ type Props = {
1213

1314
export function Pagination({ query, page, numPages, perPage }: Props) {
1415
const router = useRouter();
16+
const [isPending, startTransition] = useTransition();
1517

1618
const handlePageChange = (page: number) => {
17-
router.push(`/search?q=${query}&page=${page}&perPage=${perPage}`);
19+
startTransition(() => {
20+
router.push(
21+
`/search?q=${encodeURIComponent(query)}&page=${page}&perPage=${perPage}`,
22+
);
23+
});
1824
};
1925

2026
return (
@@ -23,6 +29,10 @@ export function Pagination({ query, page, numPages, perPage }: Props) {
2329
total={numPages}
2430
initialPage={page}
2531
onChange={handlePageChange}
32+
isDisabled={isPending}
33+
classNames={{
34+
wrapper: isPending ? "opacity-50" : "",
35+
}}
2636
/>
2737
);
2838
}

0 commit comments

Comments
 (0)