mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 16:33:49 +00:00
perf scroll components (#2676)
* perf: add scroll list && virtualist (#2665) * perf: chatHistorySlider add virtualList * perf: dataCard add scroll * fix: ts * perf: scroll list components * perf: hook refresh --------- Co-authored-by: papapatrick <109422393+Patrickill@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useCallback, useState } from 'react';
|
||||
import React, { useCallback, useMemo, useState } from 'react';
|
||||
import NextHead from '@/components/common/NextHead';
|
||||
import { useRouter } from 'next/router';
|
||||
import { delChatRecordById, getChatHistories, getInitChatInfo } from '@/web/core/chat/api';
|
||||
@@ -53,14 +53,17 @@ const Chat = ({
|
||||
|
||||
const { setLastChatAppId } = useChatStore();
|
||||
const {
|
||||
loadHistories,
|
||||
setHistories: setRecordHistories,
|
||||
loadHistories: loadRecordHistories,
|
||||
histories: recordHistories,
|
||||
onUpdateHistory,
|
||||
onClearHistories,
|
||||
onDelHistory,
|
||||
isOpenSlider,
|
||||
onCloseSlider,
|
||||
forbidLoadChat,
|
||||
onChangeChatId
|
||||
onChangeChatId,
|
||||
onUpdateHistoryTitle
|
||||
} = useContextSelector(ChatContext, (v) => v);
|
||||
const {
|
||||
ChatBoxRef,
|
||||
@@ -148,8 +151,7 @@ const Chat = ({
|
||||
if (completionChatId !== chatId && controller.signal.reason !== 'leave') {
|
||||
onChangeChatId(completionChatId, true);
|
||||
}
|
||||
loadHistories();
|
||||
|
||||
onUpdateHistoryTitle({ chatId: completionChatId, newTitle });
|
||||
// update chat window
|
||||
setChatData((state) => ({
|
||||
...state,
|
||||
@@ -158,7 +160,7 @@ const Chat = ({
|
||||
|
||||
return { responseText, responseData, isNewChat: forbidLoadChat.current };
|
||||
},
|
||||
[appId, chatId, forbidLoadChat, loadHistories, onChangeChatId]
|
||||
[chatId, appId, onUpdateHistoryTitle, forbidLoadChat, onChangeChatId]
|
||||
);
|
||||
|
||||
return (
|
||||
@@ -283,14 +285,6 @@ const Render = (props: Props) => {
|
||||
}
|
||||
);
|
||||
|
||||
const { data: histories = [], runAsync: loadHistories } = useRequest2(
|
||||
() => (appId ? getChatHistories({ appId }) : Promise.resolve([])),
|
||||
{
|
||||
manual: false,
|
||||
refreshDeps: [appId]
|
||||
}
|
||||
);
|
||||
|
||||
// 初始化聊天框
|
||||
useMount(async () => {
|
||||
// pc: redirect to latest model chat
|
||||
@@ -324,8 +318,9 @@ const Render = (props: Props) => {
|
||||
}
|
||||
});
|
||||
|
||||
const providerParams = useMemo(() => ({ appId }), [appId]);
|
||||
return (
|
||||
<ChatContextProvider histories={histories} loadHistories={loadHistories}>
|
||||
<ChatContextProvider params={providerParams}>
|
||||
<Chat {...props} myApps={myApps} />
|
||||
</ChatContextProvider>
|
||||
);
|
||||
|
Reference in New Issue
Block a user