Skip to content

Commit 68a3425

Browse files
committed
fix(frontend): fix #245
1 parent b9a2ee5 commit 68a3425

File tree

2 files changed

+14
-6
lines changed
  • apps/frontend/src/pages/tasks.[id].samples.[id]

2 files changed

+14
-6
lines changed

apps/frontend/src/pages/tasks.[id].samples.[id]/components/annotationRightCorner/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ interface AnnotationRightCornerProps {
2929
fetchNext?: () => void;
3030

3131
totalSize: number;
32+
33+
isLastPage: boolean;
3234
}
3335

3436
export const SAMPLE_CHANGED = 'sampleChanged';
@@ -63,7 +65,7 @@ export interface AnnotationLoaderData {
6365
samples: SampleListResponse;
6466
}
6567

66-
const AnnotationRightCorner = ({ noSave, fetchNext, totalSize }: AnnotationRightCornerProps) => {
68+
const AnnotationRightCorner = ({ noSave, fetchNext, totalSize, isLastPage }: AnnotationRightCornerProps) => {
6769
const isFetching = useIsFetching();
6870
const isMutating = useIsMutating();
6971
const isGlobalLoading = isFetching > 0 || isMutating > 0;
@@ -86,11 +88,11 @@ const AnnotationRightCorner = ({ noSave, fetchNext, totalSize }: AnnotationRight
8688

8789
// 第一次进入就是40的倍数时,获取下一页数据
8890
useEffect(() => {
89-
if (isLastSample && samples.length < totalSize) {
91+
if (isLastSample && samples.length < totalSize && !isLastPage) {
9092
// TODO: fetchNext 调用两次
9193
fetchNext?.();
9294
}
93-
}, [fetchNext, isLastSample, samples.length, totalSize]);
95+
}, [fetchNext, isLastSample, samples.length, totalSize, isLastPage]);
9496

9597
const navigateWithSearch = useCallback(
9698
(to: string) => {

apps/frontend/src/pages/tasks.[id].samples.[id]/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ const AnnotationPage = () => {
152152
const PAGE_SIZE = 40;
153153
// 滚动加载
154154
const [totalCount, setTotalCount] = useState<number>(0);
155+
const [serverPage, setServerPage] = useState<number>(1);
155156
const currentPage = useRef<number>(1);
156157
if (currentPage.current === 1) {
157158
currentPage.current = sample?.data.inner_id ? Math.floor(sample.data.inner_id / PAGE_SIZE) + 1 : 1;
@@ -170,7 +171,7 @@ const AnnotationPage = () => {
170171

171172
currentPage.current += 1;
172173
setTotalCount(meta_data?.total ?? 0);
173-
174+
setServerPage(meta_data?.page ?? 1);
174175
return data;
175176
}, [routeParams.taskId]);
176177
const [samples = [] as SampleResponse[], loading, setSamples, svc] = useScrollFetch(
@@ -180,14 +181,19 @@ const AnnotationPage = () => {
180181
document.querySelector('.labelu-audio__sidebar div') ||
181182
document.querySelector('.labelu-video__sidebar div'),
182183
{
183-
isEnd: () => totalCount === samples.length,
184+
isEnd: () => totalCount === samples.length || serverPage === Math.ceil(totalCount / PAGE_SIZE),
184185
},
185186
);
186187

187188
const leftSiderContent = useMemo(() => <SlideLoader />, []);
188189

189190
const topActionContent = (
190-
<AnnotationRightCorner totalSize={totalCount} fetchNext={svc} noSave={!!searchParams.get('noSave')} />
191+
<AnnotationRightCorner
192+
totalSize={totalCount}
193+
fetchNext={svc}
194+
isLastPage={serverPage >= Math.ceil(totalCount / PAGE_SIZE)}
195+
noSave={!!searchParams.get('noSave')}
196+
/>
191197
);
192198

193199
const annotationContextValue = useMemo(() => {

0 commit comments

Comments
 (0)