Skip to content

Commit 150e438

Browse files
authored
Merge pull request #1055 from topcoder-platform/PM-590-fixes
PM-589 Fix Load more logic
2 parents 374040b + 827d9e2 commit 150e438

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
@@ -111,7 +111,7 @@ const CopilotOpportunityList: FC<{}> = () => {
111111
)
112112

113113
const {
114-
data: opportunities, isValidating, size, setSize,
114+
data: opportunities, hasMoreOpportunities, isValidating, size, setSize,
115115
}: CopilotOpportunitiesResponse = useCopilotOpportunities()
116116

117117
const tableData = useMemo(() => opportunities.map(opportunity => ({
@@ -143,7 +143,7 @@ const CopilotOpportunityList: FC<{}> = () => {
143143
<Table
144144
columns={tableColumns}
145145
data={tableData}
146-
moreToLoad={isValidating || opportunities.length > 0}
146+
moreToLoad={hasMoreOpportunities}
147147
onLoadMoreClick={loadMore}
148148
onRowClick={handleRowClick}
149149
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+
hasMoreOpportunities: 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 hasMoreOpportunities = lastPage.length === PAGE_SIZE
65+
66+
return { data: opportunities, hasMoreOpportunities, isValidating, setSize: (s: number) => { setSize(s) }, size }
6367
}
6468

6569
export type CopilotOpportunityResponse = SWRResponse<CopilotOpportunity, CopilotOpportunity>

0 commit comments

Comments
 (0)