Skip to content

Commit

Permalink
fix: auto send delay (#3352)
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu authored Dec 10, 2024
1 parent fc8f73f commit fd47f73
Showing 1 changed file with 32 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import dynamic from 'next/dynamic';
import type { StreamResponseType } from '@/web/common/api/fetch';
import { useContextSelector } from 'use-context-selector';
import { useSystem } from '@fastgpt/web/hooks/useSystem';
import { useCreation, useMemoizedFn, useThrottleFn } from 'ahooks';
import { useCreation, useDebounceEffect, useMemoizedFn, useThrottleFn } from 'ahooks';
import MyIcon from '@fastgpt/web/components/common/Icon';
import { mergeChatResponseData } from '@fastgpt/global/core/chat/utils';
import { getWebReqUrl } from '@fastgpt/web/common/system/utils';
Expand Down Expand Up @@ -380,10 +380,11 @@ const ChatBox = ({
async ({ variables = {} }) => {
if (!onStartChat) return;
if (isChatting) {
toast({
title: t('chat:is_chatting'),
status: 'warning'
});
!hideInUI &&
toast({
title: t('chat:is_chatting'),
status: 'warning'
});
return;
}

Expand Down Expand Up @@ -834,27 +835,33 @@ const ChatBox = ({
}, [isReady, resetInputVal, sendPrompt]);

// Auto send prompt
useEffect(() => {
if (
isReady &&
chatBoxData?.app?.chatConfig?.autoExecute?.open &&
chatStarted &&
chatRecords.length === 0 &&
isChatRecordsLoaded
) {
sendPrompt({
text: chatBoxData?.app?.chatConfig?.autoExecute?.defaultPrompt || 'AUTO_EXECUTE',
hideInUI: true
});
useDebounceEffect(
() => {
if (
isReady &&
chatBoxData?.app?.chatConfig?.autoExecute?.open &&
chatStarted &&
chatRecords.length === 0 &&
isChatRecordsLoaded
) {
sendPrompt({
text: chatBoxData?.app?.chatConfig?.autoExecute?.defaultPrompt || 'AUTO_EXECUTE',
hideInUI: true
});
}
},
[
isReady,
chatStarted,
chatRecords.length,
isChatRecordsLoaded,
sendPrompt,
chatBoxData?.app?.chatConfig?.autoExecute
],
{
wait: 500
}
}, [
isReady,
chatStarted,
chatRecords.length,
isChatRecordsLoaded,
sendPrompt,
chatBoxData?.app?.chatConfig?.autoExecute
]);
);

// output data
useImperativeHandle(ChatBoxRef, () => ({
Expand Down

0 comments on commit fd47f73

Please sign in to comment.