feat: After the voice in the new conversation window is played, jump to the tab of the conversation #1877 (#2440)

### What problem does this PR solve?

feat: After the voice in the new conversation window is played, jump to
the tab of the conversation #1877

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2024-09-14 17:19:04 +08:00
committed by GitHub
parent b94c15ef1e
commit 1621313c0f
5 changed files with 62 additions and 31 deletions

View File

@ -32,6 +32,7 @@ import {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from 'react';
import { useSearchParams } from 'umi';
@ -340,6 +341,17 @@ export const useSendNextMessage = () => {
removeMessageById,
removeMessagesAfterCurrentMessage,
} = useSelectNextMessages();
const { data: dialog } = useFetchNextDialog();
const currentConversationIdRef = useRef<string>('');
const redirectToNewConversation = useCallback(
(isPlaying: boolean) => {
if (!conversationId && dialog?.prompt_config?.tts && !isPlaying) {
handleClickConversation(currentConversationIdRef.current);
}
},
[dialog, handleClickConversation, conversationId],
);
const sendMessage = useCallback(
async ({
@ -365,7 +377,9 @@ export const useSendNextMessage = () => {
if (currentConversationId) {
console.info('111');
// new conversation
handleClickConversation(currentConversationId);
if (!dialog?.prompt_config?.tts) {
handleClickConversation(currentConversationId);
}
} else {
console.info('222');
// fetchConversation(conversationId);
@ -373,6 +387,7 @@ export const useSendNextMessage = () => {
}
},
[
dialog,
derivedMessages,
conversationId,
handleClickConversation,
@ -390,6 +405,7 @@ export const useSendNextMessage = () => {
const data = await setConversation(message.content);
if (data.retcode === 0) {
const id = data.data.id;
currentConversationIdRef.current = id;
sendMessage({
message,
currentConversationId: id,
@ -463,6 +479,7 @@ export const useSendNextMessage = () => {
ref,
derivedMessages,
removeMessageById,
redirectToNewConversation,
};
};