fix: kb un refresh

This commit is contained in:
archer
2023-07-06 10:49:51 +08:00
parent 569772148f
commit a04b661864
4 changed files with 42 additions and 28 deletions

View File

@@ -167,6 +167,8 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
return res.json({
id: chatId || '',
model: model.chat.chatModel,
object: 'chat.completion',
created: 1688608930,
usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: 0 },
choices: [
{ message: { role: 'assistant', content: response }, finish_reason: 'stop', index: 0 }
@@ -296,6 +298,8 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
: {}),
newChatId,
id: chatId || '',
object: 'chat.completion',
created: 1688608930,
model: model.chat.chatModel,
usage: { prompt_tokens: 0, completion_tokens: 0, total_tokens: tokens },
choices: [

View File

@@ -1,4 +1,4 @@
import React, { useCallback, useState, useRef } from 'react';
import React, { useCallback, useState, useRef, useEffect } from 'react';
import {
Box,
Card,
@@ -50,11 +50,11 @@ const DataCard = ({ kbId }: { kbId: string }) => {
} = usePagination<KbDataItemType>({
api: getKbDataList,
pageSize: 24,
defaultRequest: false,
params: {
kbId,
searchText
},
defaultRequest: false
}
});
const [editInputData, setEditInputData] = useState<InputDataType>();
@@ -133,11 +133,11 @@ const DataCard = ({ kbId }: { kbId: string }) => {
refetchInterval: 5000,
enabled: qaListLen > 0 || vectorListLen > 0
});
useQuery(['getKbData', kbId], () => {
useEffect(() => {
setSearchText('');
getData(1);
return null;
});
}, [kbId]);
return (
<Box position={'relative'} px={5} pb={[1, 5]}>
@@ -314,4 +314,4 @@ const DataCard = ({ kbId }: { kbId: string }) => {
);
};
export default DataCard;
export default React.memo(DataCard);

View File

@@ -8,7 +8,7 @@ import { useUserStore } from '@/store/user';
import { KbItemType } from '@/types/plugin';
import { useScreen } from '@/hooks/useScreen';
import { getErrText } from '@/utils/tools';
import Info, { type ComponentRef } from './Info';
import { type ComponentRef } from './Info';
import Tabs from '@/components/Tabs';
import dynamic from 'next/dynamic';
import DataCard from './DataCard';
@@ -16,6 +16,9 @@ import DataCard from './DataCard';
const Test = dynamic(() => import('./Test'), {
ssr: false
});
const Info = dynamic(() => import('./Info'), {
ssr: false
});
enum TabEnum {
data = 'data',
@@ -28,7 +31,7 @@ const Detail = ({ kbId }: { kbId: string }) => {
const router = useRouter();
const { isPc } = useScreen();
const BasicInfo = useRef<ComponentRef>(null);
const { setLastKbId, kbDetail, getKbDetail, loadKbList, myKbList } = useUserStore();
const { setLastKbId, kbDetail, getKbDetail, loadKbList } = useUserStore();
const [currentTab, setCurrentTab] = useState(TabEnum.data);
const form = useForm<KbItemType>({
@@ -36,25 +39,30 @@ const Detail = ({ kbId }: { kbId: string }) => {
});
const { reset } = form;
useQuery([kbId], () => getKbDetail(kbId), {
onSuccess(res) {
kbId && setLastKbId(kbId);
if (res) {
setCurrentTab(TabEnum.data);
useQuery(
[kbId],
() => {
setCurrentTab(TabEnum.data);
return getKbDetail(kbId);
},
{
onSuccess(res) {
if (!res) return;
kbId && setLastKbId(kbId);
reset(res);
BasicInfo.current?.initInput?.(res.tags);
},
onError(err: any) {
loadKbList(true);
setLastKbId('');
router.replace(`/kb`);
toast({
title: getErrText(err, '获取知识库异常'),
status: 'error'
});
}
},
onError(err: any) {
loadKbList(true);
setLastKbId('');
router.replace(`/kb`);
toast({
title: getErrText(err, '获取知识库异常'),
status: 'error'
});
}
});
);
return (
<Flex
@@ -88,4 +96,4 @@ const Detail = ({ kbId }: { kbId: string }) => {
);
};
export default Detail;
export default React.memo(Detail);

View File

@@ -28,9 +28,11 @@ const Kb = () => {
<KbList kbId={kbId} />
</SideBar>
)}
<Box flex={'1 0 0'} w={0} h={'100%'} position={'relative'}>
{kbId && <KbDetail kbId={kbId} />}
</Box>
{!!kbId && (
<Box flex={'1 0 0'} w={0} h={'100%'} position={'relative'}>
<KbDetail kbId={kbId} />
</Box>
)}
</Flex>
);
};