feat: Add Skeleton to MessageItem before the backend returns a message and fixed the issue where ChatConfigurationModal displays old data when creating a new dialog (#99)

* feat: fixed the issue where ChatConfigurationModal displays old data when creating a new dialog

* feat: Add Skeleton to MessageItem before the backend returns a message
This commit is contained in:
balibabu
2024-03-05 19:28:44 +08:00
committed by GitHub
parent 602038ac49
commit 8b2bbd79e4
12 changed files with 117 additions and 72 deletions

View File

@ -78,12 +78,10 @@ export const useSetCurrentDialog = () => {
const setCurrentDialog = useCallback(
(dialogId: string) => {
if (dialogId) {
dispatch({
type: 'chatModel/setCurrentDialog',
payload: { id: dialogId },
});
}
dispatch({
type: 'chatModel/setCurrentDialog',
payload: { id: dialogId },
});
},
[dispatch],
);
@ -427,6 +425,12 @@ export const useSelectCurrentConversation = () => {
content: message,
id: uuid(),
} as IMessage,
{
role: MessageType.Assistant,
content: '',
id: uuid(),
reference: [],
} as IMessage,
],
};
});
@ -525,12 +529,13 @@ export const useSendMessage = () => {
const conversation: IClientConversation = useSelector(
(state: any) => state.chatModel.currentConversation,
);
const fetchConversation = useFetchConversation();
const { handleClickConversation } = useClickConversationCard();
const sendMessage = useCallback(
(message: string, id?: string) => {
dispatch({
async (message: string, id?: string) => {
const retcode = await dispatch<any>({
type: 'chatModel/completeConversation',
payload: {
conversation_id: id ?? conversationId,
@ -545,8 +550,22 @@ export const useSendMessage = () => {
],
},
});
if (retcode === 0) {
if (id) {
handleClickConversation(id);
} else {
fetchConversation(conversationId);
}
}
},
[dispatch, conversation?.message, conversationId],
[
dispatch,
conversation?.message,
conversationId,
fetchConversation,
handleClickConversation,
],
);
const handleSendMessage = useCallback(
@ -557,12 +576,11 @@ export const useSendMessage = () => {
const data = await setConversation(message);
if (data.retcode === 0) {
const id = data.data.id;
handleClickConversation(id);
sendMessage(message, id);
}
}
},
[conversationId, handleClickConversation, setConversation, sendMessage],
[conversationId, setConversation, sendMessage],
);
return { sendMessage: handleSendMessage };