diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index b430591b1..288a4fea2 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -22,8 +22,6 @@ const TabsContextInitialValue: TabsContextType = { incrementNodeId: () => 0, downloadFlow: (flow: FlowType) => {}, uploadFlow: () => {}, - lockChat: false, - setLockChat: (prevState: boolean) => {}, hardReset: () => {}, }; @@ -192,8 +190,6 @@ export function TabsProvider({ children }: { children: ReactNode }) { value={{ save, hardReset, - lockChat, - setLockChat, tabIndex, setTabIndex, flows, diff --git a/src/frontend/src/modals/chatModal/index.tsx b/src/frontend/src/modals/chatModal/index.tsx index 7bfcd7605..dbc95b025 100644 --- a/src/frontend/src/modals/chatModal/index.tsx +++ b/src/frontend/src/modals/chatModal/index.tsx @@ -24,12 +24,13 @@ export default function ChatModal({ setOpen: Function; flow: FlowType; }) { - const { updateFlow, lockChat, setLockChat } = useContext(TabsContext); + const { updateFlow } = useContext(TabsContext); const [chatValue, setChatValue] = useState(""); const [chatHistory, setChatHistory] = useState([]); const { reactFlowInstance } = useContext(typesContext); const { setErrorData, setNoticeData } = useContext(alertContext); const [ws, setWs] = useState(null); + const [lockChat, setLockChat] = useState(false); const addChatHistory = ( message: string, isSend: boolean, @@ -79,6 +80,7 @@ export default function ChatModal({ } if (data.type === "end") { addChatHistory(data.message, false, data.intermediate_steps); + setLockChat(false) } // Do something with the data received from the WebSocket }; @@ -162,25 +164,21 @@ export default function ChatModal({ chatHistory, name: flow.name, description: flow.description, - }) - .then(() => { - setLockChat(false); - }) - .catch((error) => { - setErrorData({ - title: error.message ?? "Unknown Error", - list: [error.response.data.detail], - }); - setLockChat(false); - let lastMessage; - setChatHistory((chatHistory) => { - let newChat = chatHistory; - - lastMessage = newChat.pop().message; - return newChat; - }); - setChatValue(lastMessage); + }).catch((error) => { + setErrorData({ + title: error.message ?? "Unknown Error", + list: [error.response.data.detail], }); + setLockChat(false); + let lastMessage; + setChatHistory((chatHistory) => { + let newChat = chatHistory; + + lastMessage = newChat.pop().message; + return newChat; + }); + setChatValue(lastMessage); + }); } else { setErrorData({ title: "Oops! Looks like you missed some required information:", diff --git a/src/frontend/src/types/tabs/index.ts b/src/frontend/src/types/tabs/index.ts index 6bb452b31..1b675e0c5 100644 --- a/src/frontend/src/types/tabs/index.ts +++ b/src/frontend/src/types/tabs/index.ts @@ -11,7 +11,5 @@ export type TabsContextType = { incrementNodeId: () => number; downloadFlow: (flow:FlowType) => void; uploadFlow: () => void; - lockChat:boolean; - setLockChat:(prevState:boolean)=>void; hardReset:()=>void; }; \ No newline at end of file