Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/web/hooks/useLinkedScroll.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { useRequest } from './useRequest';

const threshold = 200;

/**
* 加载以锚点为中心的关联列表,并按滚动位置补充前后数据。
* 关闭分页时仍保留滚动容器和初始锚点请求,适用于只展示单条数据的场景。
*/
export function useLinkedScroll<
TParams extends LinkedPaginationProps,
TData extends LinkedListResponse
Expand All @@ -18,12 +22,14 @@ export function useLinkedScroll<
params = {},
currentData,
defaultScroll = 'top',
enablePagination = true,
showErrorToast = true
}: {
pageSize?: number;
params?: Record<string, any>;
currentData?: { id: string; anchor?: any };
defaultScroll?: 'top' | 'bottom';
enablePagination?: boolean;
showErrorToast?: boolean;
}
) {
Expand Down Expand Up @@ -246,7 +252,7 @@ export function useLinkedScroll<

useDebounceEffect(
() => {
if (!actualContainerRef?.current || isLoading) return;
if (!enablePagination || !actualContainerRef?.current || isLoading) return;

const { scrollTop, scrollHeight, clientHeight } = actualContainerRef.current;

Expand All @@ -260,7 +266,7 @@ export function useLinkedScroll<
loadPrevData(actualContainerRef);
}
},
[scroll],
[scroll, enablePagination],
{ wait: 200 }
);

Expand All @@ -280,7 +286,7 @@ export function useLinkedScroll<
</MyBox>
);
},
[isLoading]
[enablePagination, isLoading]
);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ const CollectionReader = ({
loadInitData
} = useLinkedScroll(getCollectionQuote, {
params,
currentData: currentQuoteItem
currentData: currentQuoteItem,
enablePagination: !singleQuote
});

const isDeleted = useMemo(
Expand Down
Loading