Fix: Reset all data except the first one on the chat page shared with others #3221 (#9567)

### What problem does this PR solve?

Fix: Reset all data except the first one on the chat page shared with
others #3221

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
balibabu
2025-08-19 19:04:40 +08:00
committed by GitHub
parent d0dc56166c
commit 00f54c207e
3 changed files with 14 additions and 2 deletions

View File

@ -557,6 +557,15 @@ export const useSelectDerivedMessages = () => {
setDerivedMessages([]);
}, [setDerivedMessages]);
const removeAllMessagesExceptFirst = useCallback(() => {
setDerivedMessages((list) => {
if (list.length <= 1) {
return list;
}
return list.slice(0, 1);
});
}, [setDerivedMessages]);
return {
scrollRef,
messageContainerRef,
@ -571,6 +580,7 @@ export const useSelectDerivedMessages = () => {
removeMessagesAfterCurrentMessage,
removeAllMessages,
scrollToBottom,
removeAllMessagesExceptFirst,
};
};

View File

@ -60,6 +60,7 @@ export const useSendSharedMessage = () => {
scrollRef,
messageContainerRef,
removeAllMessages,
removeAllMessagesExceptFirst,
} = useSelectDerivedMessages();
const [hasError, setHasError] = useState(false);
@ -149,5 +150,6 @@ export const useSendSharedMessage = () => {
scrollRef,
messageContainerRef,
removeAllMessages,
removeAllMessagesExceptFirst,
};
};

View File

@ -37,7 +37,7 @@ const ChatContainer = () => {
stopOutputMessage,
scrollRef,
messageContainerRef,
removeAllMessages,
removeAllMessagesExceptFirst,
} = useSendSharedMessage();
const sendDisabled = useSendButtonDisabled(value);
const { data: chatInfo } = useFetchExternalChatInfo();
@ -63,7 +63,7 @@ const ChatContainer = () => {
<EmbedContainer
title={chatInfo.title}
avatar={chatInfo.avatar}
handleReset={removeAllMessages}
handleReset={removeAllMessagesExceptFirst}
>
<div className="flex flex-1 flex-col p-2.5 h-[90vh] m-3">
<div