Skip to content

Commit d94eee5

Browse files
author
박재현(Singco)
committed
feat(view): Implement pagination in FakeIDEAdapter for infinite scroll
- Add pagination logic to FakeIDEAdapter to simulate real data fetching for infinite scrolling. - Implement page tracking using currentPage and PAGE_SIZE to slice and return partial data. - Ensure FakeIDEAdapter is a singleton to maintain pagination state across requests. - Update message handling to support 'load more' functionality based on lastCommitId. Related to #1007
1 parent 4759782 commit d94eee5

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

packages/view/src/ide/FakeIDEAdapter.ts

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ import type IDEPort from "./IDEPort";
1010

1111
@injectable()
1212
export default class FakeIDEAdapter implements IDEPort {
13+
private currentPage = 0;
14+
15+
private readonly PAGE_SIZE = 20;
16+
17+
private readonly TOTAL_PAGES = 5;
18+
19+
private lastProcessedCommitId: string | undefined = undefined;
20+
1321
public addIDESentEventListener(events: IDESentEvents) {
1422
const onReceiveMessage = (e: IDEMessageEvent): void => {
1523
const responseMessage = e.data;
@@ -80,21 +88,55 @@ export default class FakeIDEAdapter implements IDEPort {
8088
}
8189

8290
private convertMessage(message: IDEMessage) {
83-
const { command } = message;
91+
const { command, payload } = message;
8492

8593
switch (command) {
8694
case "fetchAnalyzedData":
87-
case "refresh":
95+
case "refresh": {
96+
// Parse request params to check if this is a load more request
97+
const requestParams = payload ? JSON.parse(payload) : undefined;
98+
const currentCommitId = requestParams?.lastCommitId;
99+
100+
// Reset page on refresh command
101+
if (command === "refresh") {
102+
this.currentPage = 0;
103+
this.lastProcessedCommitId = undefined;
104+
}
105+
// Reset page on first load (no lastCommitId)
106+
else if (!currentCommitId) {
107+
this.currentPage = 0;
108+
this.lastProcessedCommitId = undefined;
109+
}
110+
// Increment page only when we get a NEW lastCommitId (load more)
111+
else if (currentCommitId !== this.lastProcessedCommitId) {
112+
this.currentPage += 1;
113+
this.lastProcessedCommitId = currentCommitId;
114+
}
115+
116+
// Calculate pagination
117+
const startIdx = this.currentPage * this.PAGE_SIZE;
118+
const endIdx = Math.min(startIdx + this.PAGE_SIZE, fakeData.length);
119+
const pageData = fakeData.slice(startIdx, endIdx);
120+
const isLastPage = this.currentPage >= this.TOTAL_PAGES - 1;
121+
122+
// Get the last commit ID from the current page for nextCommitId
123+
const lastCommitInPage =
124+
pageData.length > 0 ? pageData[pageData.length - 1].commitNodeList[0]?.commit : undefined;
125+
const nextCommitId = !isLastPage && lastCommitInPage ? lastCommitInPage.id : undefined;
126+
127+
const isLoadMore = currentCommitId !== undefined;
128+
88129
return {
89130
command,
90131
payload: JSON.stringify({
91-
clusterNodes: fakeData,
92-
isLastPage: true,
93-
nextCommitId: undefined,
94-
isLoadMore: false,
132+
clusterNodes: pageData,
133+
isLastPage,
134+
nextCommitId,
135+
isLoadMore,
95136
isPRSuccess: true,
96137
}),
97138
};
139+
}
98140
case "fetchBranchList":
99141
return {
100142
command,

packages/view/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ import { DI_IDENTIFIERS } from "container/identifiers";
77

88
import { initRender } from "./index.common";
99

10-
diContainer.bind<IDEPort>(DI_IDENTIFIERS.IDEAdapter).to(FakeIDEAdapter);
10+
diContainer.bind<IDEPort>(DI_IDENTIFIERS.IDEAdapter).to(FakeIDEAdapter).inSingletonScope();
1111

1212
initRender();

0 commit comments

Comments
 (0)