Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions web/src/hooks/flow-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,17 @@ export const useFetchFlowList = (): { data: IFlow[]; loading: boolean } => {
return { data, loading };
};

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

return { data, loading };
return { data, loading, refetch };
};

export const useSetFlow = () => {
Expand Down
10 changes: 6 additions & 4 deletions web/src/pages/flow/canvas/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
);
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/flow/chat/drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
>
Expand Down
28 changes: 13 additions & 15 deletions web/src/pages/flow/chat/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
];
});
}, []);

Expand Down Expand Up @@ -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);
Expand All @@ -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(
Expand Down