Commit 934776f4 by Xianquan Committed by GitHub

fix(chat): stop single quote pagination loop (#7426)

parent 09896e77
...@@ -8,6 +8,10 @@ import { useRequest } from './useRequest'; ...@@ -8,6 +8,10 @@ import { useRequest } from './useRequest';
const threshold = 200; const threshold = 200;
/**
* 加载以锚点为中心的关联列表,并按滚动位置补充前后数据。
* 关闭分页时仍保留滚动容器和初始锚点请求,适用于只展示单条数据的场景。
*/
export function useLinkedScroll< export function useLinkedScroll<
TParams extends LinkedPaginationProps, TParams extends LinkedPaginationProps,
TData extends LinkedListResponse TData extends LinkedListResponse
...@@ -18,12 +22,14 @@ export function useLinkedScroll< ...@@ -18,12 +22,14 @@ export function useLinkedScroll<
params = {}, params = {},
currentData, currentData,
defaultScroll = 'top', defaultScroll = 'top',
enablePagination = true,
showErrorToast = true showErrorToast = true
}: { }: {
pageSize?: number; pageSize?: number;
params?: Record<string, any>; params?: Record<string, any>;
currentData?: { id: string; anchor?: any }; currentData?: { id: string; anchor?: any };
defaultScroll?: 'top' | 'bottom'; defaultScroll?: 'top' | 'bottom';
enablePagination?: boolean;
showErrorToast?: boolean; showErrorToast?: boolean;
} }
) { ) {
...@@ -246,7 +252,7 @@ export function useLinkedScroll< ...@@ -246,7 +252,7 @@ export function useLinkedScroll<
useDebounceEffect( useDebounceEffect(
() => { () => {
if (!actualContainerRef?.current || isLoading) return; if (!enablePagination || !actualContainerRef?.current || isLoading) return;
const { scrollTop, scrollHeight, clientHeight } = actualContainerRef.current; const { scrollTop, scrollHeight, clientHeight } = actualContainerRef.current;
...@@ -260,7 +266,7 @@ export function useLinkedScroll< ...@@ -260,7 +266,7 @@ export function useLinkedScroll<
loadPrevData(actualContainerRef); loadPrevData(actualContainerRef);
} }
}, },
[scroll], [scroll, enablePagination],
{ wait: 200 } { wait: 200 }
); );
...@@ -280,7 +286,7 @@ export function useLinkedScroll< ...@@ -280,7 +286,7 @@ export function useLinkedScroll<
</MyBox> </MyBox>
); );
}, },
[isLoading] [enablePagination, isLoading]
); );
return { return {
......
...@@ -111,7 +111,8 @@ const CollectionReader = ({ ...@@ -111,7 +111,8 @@ const CollectionReader = ({
loadInitData loadInitData
} = useLinkedScroll(getCollectionQuote, { } = useLinkedScroll(getCollectionQuote, {
params, params,
currentData: currentQuoteItem currentData: currentQuoteItem,
enablePagination: !singleQuote
}); });
const isDeleted = useMemo( const isDeleted = useMemo(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment