From 0b46593202edd0025a7c5474ad46dc6fa996adf0 Mon Sep 17 00:00:00 2001 From: Jasan Gill <56135840+jasangill1@users.noreply.github.com> Date: Sat, 8 Jul 2023 14:02:53 -0700 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Fixed=20Loss=20of=20Agent=20Data=20?= =?UTF-8?q?upon=20Login=20(#991)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- next/src/pages/index.tsx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/next/src/pages/index.tsx b/next/src/pages/index.tsx index b610b421a0..bf570d1fb2 100644 --- a/next/src/pages/index.tsx +++ b/next/src/pages/index.tsx @@ -92,6 +92,7 @@ const Home: NextPage = () => { const handleNewAgent = (name: string, goal: string) => { if (session === null) { + storeAgentDataInLocalStorage(name, goal); setShowSignInDialog(true); return; } @@ -121,6 +122,28 @@ const Home: NextPage = () => { newAgent?.run().then(console.log).catch(console.error); }; + const storeAgentDataInLocalStorage = (name: string, goal: string) => { + const agentData = { name, goal }; + localStorage.setItem("agentData", JSON.stringify(agentData)); + }; + + const getAgentDataFromLocalStorage = () => { + const agentData = localStorage.getItem("agentData"); + return agentData ? JSON.parse(agentData) : null; + }; + + useEffect(() => { + if (session !== null) { + const agentData = getAgentDataFromLocalStorage(); + + if (agentData) { + setNameInput(agentData.name); + setGoalInput(agentData.goal); + localStorage.removeItem("agentData"); + } + } + }, [session]); + const handleRestart = () => { resetAllMessageSlices(); resetAllTaskSlices();