Skip to content

Commit b24648c

Browse files
author
himaniraghav3
committed
Fix Load more logic
1 parent a34c0bd commit b24648c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/apps/copilots/src/pages/copilot-opportunity-list/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const CopilotOpportunityList: FC<{}> = () => {
103103
const navigate = useNavigate()
104104

105105
const {
106-
data: opportunities, isValidating, size, setSize,
106+
data: opportunities, hasMore, isValidating, size, setSize,
107107
}: CopilotOpportunitiesResponse = useCopilotOpportunities()
108108

109109
const tableData = useMemo(() => opportunities.map(opportunity => ({
@@ -129,7 +129,7 @@ const CopilotOpportunityList: FC<{}> = () => {
129129
<Table
130130
columns={tableColumns}
131131
data={tableData}
132-
moreToLoad={isValidating || opportunities.length > 0}
132+
moreToLoad={hasMore}
133133
onLoadMoreClick={loadMore}
134134
onRowClick={handleRowClick}
135135
removeDefaultSort

src/apps/copilots/src/services/copilot-opportunities.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function copilotOpportunityFactory(data: any): CopilotOpportunity {
2929
export interface CopilotOpportunitiesResponse {
3030
isValidating: boolean;
3131
data: CopilotOpportunity[];
32+
hasMore: boolean,
3233
size: number;
3334
setSize: (size: number) => void;
3435
}
@@ -59,7 +60,10 @@ export const useCopilotOpportunities = (): CopilotOpportunitiesResponse => {
5960
// Flatten data array
6061
const opportunities = data ? data.flat() : []
6162

62-
return { data: opportunities, isValidating, setSize: (s: number) => { setSize(s) }, size }
63+
const lastPage = data[data.length - 1] || []
64+
const hasMore = lastPage.length === PAGE_SIZE
65+
66+
return { data: opportunities, hasMore, isValidating, setSize: (s: number) => { setSize(s) }, size }
6367
}
6468

6569
export type CopilotOpportunityResponse = SWRResponse<CopilotOpportunity, CopilotOpportunity>

0 commit comments

Comments
 (0)