mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 05:12:39 +00:00
4.8.19-feature (#3636)
* feat: sync org from wecom, pref: member list pagination (#3549) * feat: sync org * chore: fe * chore: loading * chore: type * pref: team member list change to pagination. Edit a sort of list apis. * feat: member update avatar * chore: user avatar move to tmb * chore: init scripts move user avatar * chore: sourceMember * fix: list api sourceMember * fix: member sync * fix: pagination * chore: adjust code * chore: move changeOwner to pro * chore: init v4819 script * chore: adjust code * chore: UserBox * perf: scroll page code * perf: list data * docs:更新用户答疑 (#3576) * docs: add custom uid docs (#3572) * fix: pagination bug (#3577) * 4.8.19 test (#3584) * faet: dataset search filter * fix: scroll page * fix: collection list api old version (#3591) * fix: collection list api format * fix: type error of addSourceMemeber * fix: scroll fetch (#3592) * fix: yuque dataset file folder can enter (#3593) * perf: load members;perf: yuque load;fix: workflow llm params cannot close (#3594) * chat openapi doc * feat: dataset openapi doc * perf: load members * perf: member load code * perf: yuque load * fix: workflow llm params cannot close * fix: api dataset reference tag preview (#3600) * perf: doc * feat: chat page config * fix: http parse (#3634) * update doc * fix: http parse * fix code run node reset template (#3633) Co-authored-by: Archer <545436317@qq.com> * docs:faq (#3627) * docs:faq * docsFix * perf: sleep plugin * fix: selector --------- Co-authored-by: Finley Ge <32237950+FinleyGe@users.noreply.github.com> Co-authored-by: Jiangween <145003935+Jiangween@users.noreply.github.com> Co-authored-by: heheer <heheer@sealos.io>
This commit is contained in:
@@ -4,7 +4,6 @@ import { ArrowBackIcon, ArrowForwardIcon } from '@chakra-ui/icons';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { useToast } from './useToast';
|
||||
import { getErrText } from '@fastgpt/global/common/error/utils';
|
||||
|
||||
import {
|
||||
useBoolean,
|
||||
useLockFn,
|
||||
@@ -14,37 +13,33 @@ import {
|
||||
useThrottleEffect
|
||||
} from 'ahooks';
|
||||
|
||||
import { PaginationProps, PaginationResponse } from '../common/fetch/type';
|
||||
|
||||
const thresholdVal = 200;
|
||||
|
||||
type PagingData<T> = {
|
||||
pageNum: number;
|
||||
pageSize: number;
|
||||
data: T[];
|
||||
total?: number;
|
||||
};
|
||||
|
||||
export function usePagination<ResT = any>({
|
||||
api,
|
||||
pageSize = 10,
|
||||
params = {},
|
||||
defaultRequest = true,
|
||||
type = 'button',
|
||||
onChange,
|
||||
refreshDeps,
|
||||
scrollLoadType = 'bottom',
|
||||
EmptyTip
|
||||
}: {
|
||||
api: (data: any) => Promise<PagingData<ResT>>;
|
||||
pageSize?: number;
|
||||
params?: Record<string, any>;
|
||||
defaultRequest?: boolean;
|
||||
type?: 'button' | 'scroll';
|
||||
onChange?: (pageNum: number) => void;
|
||||
refreshDeps?: any[];
|
||||
throttleWait?: number;
|
||||
scrollLoadType?: 'top' | 'bottom';
|
||||
EmptyTip?: React.JSX.Element;
|
||||
}) {
|
||||
export function usePagination<DataT, ResT = {}>(
|
||||
api: (data: PaginationProps<DataT>) => Promise<PaginationResponse<ResT>>,
|
||||
{
|
||||
pageSize = 10,
|
||||
params,
|
||||
defaultRequest = true,
|
||||
type = 'button',
|
||||
onChange,
|
||||
refreshDeps,
|
||||
scrollLoadType = 'bottom',
|
||||
EmptyTip
|
||||
}: {
|
||||
pageSize?: number;
|
||||
params?: DataT;
|
||||
defaultRequest?: boolean;
|
||||
type?: 'button' | 'scroll';
|
||||
onChange?: (pageNum: number) => void;
|
||||
refreshDeps?: any[];
|
||||
throttleWait?: number;
|
||||
scrollLoadType?: 'top' | 'bottom';
|
||||
EmptyTip?: React.JSX.Element;
|
||||
}
|
||||
) {
|
||||
const { toast } = useToast();
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -64,7 +59,7 @@ export function usePagination<ResT = any>({
|
||||
setTrue();
|
||||
|
||||
try {
|
||||
const res: PagingData<ResT> = await api({
|
||||
const res = await api({
|
||||
pageNum: num,
|
||||
pageSize,
|
||||
...params
|
||||
@@ -93,13 +88,13 @@ export function usePagination<ResT = any>({
|
||||
);
|
||||
}
|
||||
|
||||
setData((prevData) => (num === 1 ? res.data : [...res.data, ...prevData]));
|
||||
setData((prevData) => (num === 1 ? res.list : [...res.list, ...prevData]));
|
||||
adjustScrollPosition();
|
||||
} else {
|
||||
setData((prevData) => (num === 1 ? res.data : [...prevData, ...res.data]));
|
||||
setData((prevData) => (num === 1 ? res.list : [...prevData, ...res.list]));
|
||||
}
|
||||
} else {
|
||||
setData(res.data);
|
||||
setData(res.list);
|
||||
}
|
||||
|
||||
onChange?.(num);
|
||||
|
@@ -16,7 +16,7 @@ import MyBox from '../components/common/MyBox';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
|
||||
type ItemHeight<T> = (index: number, data: T) => number;
|
||||
const thresholdVal = 200;
|
||||
const thresholdVal = 100;
|
||||
|
||||
export type ScrollListType = ({
|
||||
children,
|
||||
@@ -269,8 +269,10 @@ export function useScrollPagination<
|
||||
({
|
||||
children,
|
||||
ScrollContainerRef,
|
||||
isLoading,
|
||||
...props
|
||||
}: {
|
||||
isLoading?: boolean;
|
||||
children: ReactNode;
|
||||
ScrollContainerRef?: RefObject<HTMLDivElement>;
|
||||
} & BoxProps) => {
|
||||
@@ -302,7 +304,7 @@ export function useScrollPagination<
|
||||
);
|
||||
|
||||
return (
|
||||
<Box {...props} ref={ref} overflow={'overlay'}>
|
||||
<MyBox {...props} ref={ref} overflow={'overlay'} isLoading={isLoading}>
|
||||
{scrollLoadType === 'top' && total > 0 && isLoading && (
|
||||
<Box mt={2} fontSize={'xs'} color={'blackAlpha.500'} textAlign={'center'}>
|
||||
{t('common:common.is_requesting')}
|
||||
@@ -325,7 +327,7 @@ export function useScrollPagination<
|
||||
</Box>
|
||||
)}
|
||||
{isEmpty && EmptyTip}
|
||||
</Box>
|
||||
</MyBox>
|
||||
);
|
||||
}
|
||||
);
|
||||
|
Reference in New Issue
Block a user