### What problem does this PR solve? Fix: When I click to interrupt the chat, the page reports an error #10553 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
24 lines
791 B
TypeScript
24 lines
791 B
TypeScript
import { useClickConversationCard } from '@/hooks/use-chat-request';
|
|
import { useCallback, useState } from 'react';
|
|
|
|
export function useHandleClickConversationCard() {
|
|
const [controller, setController] = useState(new AbortController());
|
|
const { handleClickConversation } = useClickConversationCard();
|
|
|
|
const stopOutputMessage = useCallback(() => {
|
|
setController((pre) => {
|
|
pre.abort();
|
|
return new AbortController();
|
|
});
|
|
}, []);
|
|
|
|
const handleConversationCardClick = useCallback(
|
|
(conversationId: string, isNew: boolean) => {
|
|
handleClickConversation(conversationId, isNew ? 'true' : '');
|
|
stopOutputMessage();
|
|
},
|
|
[handleClickConversation, stopOutputMessage],
|
|
);
|
|
|
|
return { controller, handleConversationCardClick, stopOutputMessage };
|
|
}
|