Skip to content

Commit 64904c8

Browse files
committed
refactor: simplify Pagination logic and adjust default page size in ScorecardList
- Removed redundant page size options from `Pagination` to streamline the component. - Updated default `pageSize` from 8 to 10 for consistency across hooks and pagination logic. - Added safeguard in `onPageChange` to prevent navigating beyond available pages.
1 parent efb6cbd commit 64904c8

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/modules/ScorecardList/components/ScorecardListArea.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,7 @@ export function ScorecardListArea() {
6464
</div>
6565
</Suspense>
6666
<div className="p-16 w-full">
67-
<Pagination
68-
className="!w-full !max-w-full"
69-
disabled={pager.pageCount === 1 || isEmpty(scorecards)}
70-
{...pager}
71-
pageSizes={Array.from(new Array(10).keys()).map((i) =>
72-
((i + 1) * 4).toString()
73-
)}
74-
/>
67+
<Pagination className="!w-full !max-w-full" {...pager} />
7568
</div>
7669
</div>
7770
);

src/modules/ScorecardList/hooks/data.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function useScorecardListData() {
6666
useDataQuery<ListDataQueryResponse>(query, {
6767
variables: {
6868
page: searchParams.get("page") ?? 1,
69-
pageSize: searchParams.get("pageSize") ?? 8,
69+
pageSize: searchParams.get("pageSize") ?? 10,
7070
keyword: searchParams.get("query"),
7171
},
7272
lazy: true,
@@ -80,7 +80,7 @@ export function useScorecardListData() {
8080
refetch({
8181
keyword,
8282
page: 1,
83-
pageSize: 8,
83+
pageSize: 10,
8484
});
8585
}, 1000);
8686

@@ -93,13 +93,16 @@ export function useScorecardListData() {
9393
parseInt(searchParams.get("page") ?? "1"),
9494
pageSize:
9595
data?.list?.pager?.pageSize ??
96-
parseInt(searchParams.get("pageSize") ?? "8"),
97-
pageCount: Math.ceil(total / (data?.list?.pager?.pageSize ?? 8)),
96+
parseInt(searchParams.get("pageSize") ?? "10"),
97+
pageCount: Math.ceil(total / (data?.list?.pager?.pageSize ?? 10)),
9898
total,
9999
};
100100
}, [data]);
101101

102102
const onPageChange = (page: number) => {
103+
if (page > pager.pageCount) {
104+
return;
105+
}
103106
setSearchParams((prev) => {
104107
const updatedParams = new URLSearchParams(prev);
105108
updatedParams.set("page", page.toString());
@@ -119,7 +122,7 @@ export function useScorecardListData() {
119122
refetch({
120123
keyword: searchParams.get("query"),
121124
page: searchParams.get("page") ?? 1,
122-
pageSize: searchParams.get("pageSize") ?? 8,
125+
pageSize: searchParams.get("pageSize") ?? 10,
123126
});
124127
}, [searchParams.get("page"), searchParams.get("pageSize")]);
125128

0 commit comments

Comments
 (0)