Skip to content

Commit

Permalink
✨ Fixed Loss of Agent Data upon Login (#991)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasangill1 authored Jul 8, 2023
1 parent 3b27ce0 commit 0b46593
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions next/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const Home: NextPage = () => {

const handleNewAgent = (name: string, goal: string) => {
if (session === null) {
storeAgentDataInLocalStorage(name, goal);
setShowSignInDialog(true);
return;
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 0b46593

Please sign in to comment.