feat: pull the message list after sending the message successfully #918 (#1364)

### What problem does this PR solve?

feat: pull the message list after sending the message successfully #918

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2024-07-04 09:55:08 +08:00
committed by GitHub
parent 745e98e56a
commit dec3bf7503
4 changed files with 31 additions and 23 deletions

View File

@ -133,10 +133,12 @@ function FlowCanvas({ chatDrawerVisible, hideChatDrawer }: IProps) {
visible={drawerVisible}
hideModal={hideDrawer}
></FlowDrawer>
<ChatDrawer
visible={chatDrawerVisible}
hideModal={hideChatDrawer}
></ChatDrawer>
{chatDrawerVisible && (
<ChatDrawer
visible={chatDrawerVisible}
hideModal={hideChatDrawer}
></ChatDrawer>
)}
</div>
);
}

View File

@ -10,7 +10,7 @@ const ChatDrawer = ({ visible, hideModal }: IModalProps<any>) => {
onClose={hideModal}
open={visible}
getContainer={false}
width={470}
width={window.innerWidth > 1278 ? '30%' : 470}
mask={false}
// zIndex={10000}
>

View File

@ -48,19 +48,15 @@ export const useSelectCurrentMessages = () => {
const addNewestAnswer = useCallback((answer: IAnswer) => {
setCurrentMessages((pre) => {
const latestMessage = pre?.at(-1);
if (latestMessage) {
return [
...pre.slice(0, -1),
{
...latestMessage,
content: answer.answer,
reference: answer.reference,
},
];
}
return pre;
return [
...pre.slice(0, -1),
{
id: uuid(),
role: MessageType.Assistant,
content: answer.answer,
reference: answer.reference,
},
];
});
}, []);
@ -97,7 +93,7 @@ export const useSendMessage = (
) => {
const { id: flowId } = useParams();
const { handleInputChange, value, setValue } = useHandleMessageInputChange();
const { data: flowDetail } = useFetchFlow();
const { data: flowDetail, refetch } = useFetchFlow();
const messages = flowDetail.dsl.messages;
const { send, answer, done } = useSendMessageWithSse(api.runCanvas);
@ -118,9 +114,11 @@ export const useSendMessage = (
// cancel loading
setValue(message);
removeLatestMessage();
} else {
refetch(); // pull the message list after sending the message successfully
}
},
[flowId, removeLatestMessage, setValue, send],
[flowId, removeLatestMessage, setValue, send, refetch],
);
const handleSendMessage = useCallback(