fix simple snapshot init & auto excute when change app (#3293)

This commit is contained in:
heheer
2024-12-02 21:40:31 +08:00
committed by GitHub
parent 1cef206c13
commit c506442993
8 changed files with 49 additions and 36 deletions

View File

@@ -63,15 +63,20 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
// Load chat init data
const [chatData, setChatData] = useState<InitChatResponse>(defaultChatData);
const { loading: isLoading } = useRequest2(
const { loading } = useRequest2(
async () => {
if (!appId || forbidLoadChat.current) return;
const res = await getInitChatInfo({ appId, chatId });
res.userAvatar = userInfo?.avatar;
setChatData(res);
setChatBoxData(res);
// Wait for state update to complete
await new Promise((resolve) => {
setChatData(res);
setChatBoxData(res);
setTimeout(resolve, 0);
});
// reset chat variables
resetVariables({
variables: res.variables
@@ -136,8 +141,6 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
},
[chatId, appId, onUpdateHistoryTitle, forbidLoadChat]
);
const loading = isLoading;
const RenderHistorySlider = useMemo(() => {
const Children = (
<ChatHistorySlider confirmClearText={t('common:core.chat.Confirm to clear history')} />
@@ -210,6 +213,7 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
feedbackType={'user'}
onStartChat={onStartChat}
chatType={'chat'}
isReady={!loading}
showRawSource
showNodeStatus
/>

View File

@@ -88,7 +88,7 @@ const OutLink = (props: Props) => {
const initSign = useRef(false);
const [chatData, setChatData] = useState<InitChatResponse>(defaultChatData);
const { data, loading: isLoading } = useRequest2(
const { data, loading } = useRequest2(
async () => {
const shareId = outLinkAuthData.shareId;
const outLinkUid = outLinkAuthData.outLinkUid;
@@ -100,8 +100,12 @@ const OutLink = (props: Props) => {
outLinkUid
});
setChatData(res);
setChatBoxData(res);
await new Promise((resolve) => {
setChatData(res);
setChatBoxData(res);
setTimeout(resolve, 0);
});
resetVariables({
variables: res.variables
});
@@ -231,8 +235,6 @@ const OutLink = (props: Props) => {
);
}, [isOpenSlider, isPc, onCloseSlider, showHistory, t]);
const loading = isLoading;
return (
<>
<NextHead title={props.appName || 'AI'} desc={props.appIntro} icon={props.appAvatar} />
@@ -280,6 +282,7 @@ const OutLink = (props: Props) => {
feedbackType={'user'}
onStartChat={startChat}
chatType="share"
isReady={!loading}
showRawSource={showRawSource}
showNodeStatus={showNodeStatus}
/>

View File

@@ -69,14 +69,17 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
// get chat app info
const [chatData, setChatData] = useState<InitChatResponse>(defaultChatData);
const { loading: isLoading } = useRequest2(
const { loading } = useRequest2(
async () => {
if (!appId || forbidLoadChat.current) return;
const res = await getTeamChatInfo({ teamId, appId, chatId, teamToken });
setChatData(res);
setChatBoxData(res);
await new Promise((resolve) => {
setChatData(res);
setChatBoxData(res);
setTimeout(resolve, 0);
});
// reset chat records
resetVariables({
variables: res.variables
@@ -177,8 +180,6 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
);
}, [appId, isOpenSlider, isPc, onCloseSlider, t]);
const loading = isLoading;
return (
<Flex h={'100%'}>
<NextHead title={chatData.app.name} icon={chatData.app.avatar}></NextHead>
@@ -226,6 +227,7 @@ const Chat = ({ myApps }: { myApps: AppListItemType[] }) => {
feedbackType={'user'}
onStartChat={startChat}
chatType="team"
isReady={!loading}
showRawSource
showNodeStatus
/>