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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 31 additions and 23 deletions

View File

@ -80,9 +80,17 @@ export const useFetchFlowList = (): { data: IFlow[]; loading: boolean } => {
return { data, loading }; return { data, loading };
}; };
export const useFetchFlow = (): { data: IFlow; loading: boolean } => { export const useFetchFlow = (): {
data: IFlow;
loading: boolean;
refetch: () => void;
} => {
const { id } = useParams(); const { id } = useParams();
const { data, isFetching: loading } = useQuery({ const {
data,
isFetching: loading,
refetch,
} = useQuery({
queryKey: ['flowDetail'], queryKey: ['flowDetail'],
initialData: {} as IFlow, initialData: {} as IFlow,
queryFn: async () => { queryFn: async () => {
@ -92,7 +100,7 @@ export const useFetchFlow = (): { data: IFlow; loading: boolean } => {
}, },
}); });
return { data, loading }; return { data, loading, refetch };
}; };
export const useSetFlow = () => { export const useSetFlow = () => {

View File

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

View File

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

View File

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