balibabu
commited on
Commit
·
69e5f04
1
Parent(s):
023bae0
feat: pull the message list after sending the message successfully #918 (#1364)
Browse files### 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)
web/src/hooks/flow-hooks.ts
CHANGED
|
@@ -80,9 +80,17 @@ export const useFetchFlowList = (): { data: IFlow[]; loading: boolean } => {
|
|
| 80 |
return { data, loading };
|
| 81 |
};
|
| 82 |
|
| 83 |
-
export const useFetchFlow = (): {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
const { id } = useParams();
|
| 85 |
-
const {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
queryKey: ['flowDetail'],
|
| 87 |
initialData: {} as IFlow,
|
| 88 |
queryFn: async () => {
|
|
@@ -92,7 +100,7 @@ export const useFetchFlow = (): { data: IFlow; loading: boolean } => {
|
|
| 92 |
},
|
| 93 |
});
|
| 94 |
|
| 95 |
-
return { data, loading };
|
| 96 |
};
|
| 97 |
|
| 98 |
export const useSetFlow = () => {
|
|
|
|
| 80 |
return { data, loading };
|
| 81 |
};
|
| 82 |
|
| 83 |
+
export const useFetchFlow = (): {
|
| 84 |
+
data: IFlow;
|
| 85 |
+
loading: boolean;
|
| 86 |
+
refetch: () => void;
|
| 87 |
+
} => {
|
| 88 |
const { id } = useParams();
|
| 89 |
+
const {
|
| 90 |
+
data,
|
| 91 |
+
isFetching: loading,
|
| 92 |
+
refetch,
|
| 93 |
+
} = useQuery({
|
| 94 |
queryKey: ['flowDetail'],
|
| 95 |
initialData: {} as IFlow,
|
| 96 |
queryFn: async () => {
|
|
|
|
| 100 |
},
|
| 101 |
});
|
| 102 |
|
| 103 |
+
return { data, loading, refetch };
|
| 104 |
};
|
| 105 |
|
| 106 |
export const useSetFlow = () => {
|
web/src/pages/flow/canvas/index.tsx
CHANGED
|
@@ -133,10 +133,12 @@ function FlowCanvas({ chatDrawerVisible, hideChatDrawer }: IProps) {
|
|
| 133 |
visible={drawerVisible}
|
| 134 |
hideModal={hideDrawer}
|
| 135 |
></FlowDrawer>
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
| 140 |
</div>
|
| 141 |
);
|
| 142 |
}
|
|
|
|
| 133 |
visible={drawerVisible}
|
| 134 |
hideModal={hideDrawer}
|
| 135 |
></FlowDrawer>
|
| 136 |
+
{chatDrawerVisible && (
|
| 137 |
+
<ChatDrawer
|
| 138 |
+
visible={chatDrawerVisible}
|
| 139 |
+
hideModal={hideChatDrawer}
|
| 140 |
+
></ChatDrawer>
|
| 141 |
+
)}
|
| 142 |
</div>
|
| 143 |
);
|
| 144 |
}
|
web/src/pages/flow/chat/drawer.tsx
CHANGED
|
@@ -10,7 +10,7 @@ const ChatDrawer = ({ visible, hideModal }: IModalProps<any>) => {
|
|
| 10 |
onClose={hideModal}
|
| 11 |
open={visible}
|
| 12 |
getContainer={false}
|
| 13 |
-
width={470}
|
| 14 |
mask={false}
|
| 15 |
// zIndex={10000}
|
| 16 |
>
|
|
|
|
| 10 |
onClose={hideModal}
|
| 11 |
open={visible}
|
| 12 |
getContainer={false}
|
| 13 |
+
width={window.innerWidth > 1278 ? '30%' : 470}
|
| 14 |
mask={false}
|
| 15 |
// zIndex={10000}
|
| 16 |
>
|
web/src/pages/flow/chat/hooks.ts
CHANGED
|
@@ -48,19 +48,15 @@ export const useSelectCurrentMessages = () => {
|
|
| 48 |
|
| 49 |
const addNewestAnswer = useCallback((answer: IAnswer) => {
|
| 50 |
setCurrentMessages((pre) => {
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
},
|
| 61 |
-
];
|
| 62 |
-
}
|
| 63 |
-
return pre;
|
| 64 |
});
|
| 65 |
}, []);
|
| 66 |
|
|
@@ -97,7 +93,7 @@ export const useSendMessage = (
|
|
| 97 |
) => {
|
| 98 |
const { id: flowId } = useParams();
|
| 99 |
const { handleInputChange, value, setValue } = useHandleMessageInputChange();
|
| 100 |
-
const { data: flowDetail } = useFetchFlow();
|
| 101 |
const messages = flowDetail.dsl.messages;
|
| 102 |
|
| 103 |
const { send, answer, done } = useSendMessageWithSse(api.runCanvas);
|
|
@@ -118,9 +114,11 @@ export const useSendMessage = (
|
|
| 118 |
// cancel loading
|
| 119 |
setValue(message);
|
| 120 |
removeLatestMessage();
|
|
|
|
|
|
|
| 121 |
}
|
| 122 |
},
|
| 123 |
-
[flowId, removeLatestMessage, setValue, send],
|
| 124 |
);
|
| 125 |
|
| 126 |
const handleSendMessage = useCallback(
|
|
|
|
| 48 |
|
| 49 |
const addNewestAnswer = useCallback((answer: IAnswer) => {
|
| 50 |
setCurrentMessages((pre) => {
|
| 51 |
+
return [
|
| 52 |
+
...pre.slice(0, -1),
|
| 53 |
+
{
|
| 54 |
+
id: uuid(),
|
| 55 |
+
role: MessageType.Assistant,
|
| 56 |
+
content: answer.answer,
|
| 57 |
+
reference: answer.reference,
|
| 58 |
+
},
|
| 59 |
+
];
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
});
|
| 61 |
}, []);
|
| 62 |
|
|
|
|
| 93 |
) => {
|
| 94 |
const { id: flowId } = useParams();
|
| 95 |
const { handleInputChange, value, setValue } = useHandleMessageInputChange();
|
| 96 |
+
const { data: flowDetail, refetch } = useFetchFlow();
|
| 97 |
const messages = flowDetail.dsl.messages;
|
| 98 |
|
| 99 |
const { send, answer, done } = useSendMessageWithSse(api.runCanvas);
|
|
|
|
| 114 |
// cancel loading
|
| 115 |
setValue(message);
|
| 116 |
removeLatestMessage();
|
| 117 |
+
} else {
|
| 118 |
+
refetch(); // pull the message list after sending the message successfully
|
| 119 |
}
|
| 120 |
},
|
| 121 |
+
[flowId, removeLatestMessage, setValue, send, refetch],
|
| 122 |
);
|
| 123 |
|
| 124 |
const handleSendMessage = useCallback(
|