diff --git a/packages/frontend/components/Sidebar/Sidebar.tsx b/packages/frontend/components/Sidebar/Sidebar.tsx index af5d7459..e1ff8ff6 100644 --- a/packages/frontend/components/Sidebar/Sidebar.tsx +++ b/packages/frontend/components/Sidebar/Sidebar.tsx @@ -338,7 +338,7 @@ interface SidebarContainerProps { renderCoopBlock?: boolean; renderBetaMajorBlock?: boolean; renderDropdownWarning?: boolean; - planId: string | number; + planId?: string | number; } export const NoPlanSidebar: React.FC = () => { @@ -358,18 +358,23 @@ const SidebarContainer: React.FC> = ({ }) => { const [notes, setNotes] = useState(""); const handleNewNotes = (e: React.ChangeEvent) => { + if (!planId) return; setNotes(e.target.value); + // Retrieve existing notes from localStorage + const storedNotes = localStorage.getItem("notes"); + const notesObject = storedNotes ? JSON.parse(storedNotes) : {}; + notesObject[planId] = notes; // have a notes object plan_id (number | string) -> note (string) - localStorage.setItem(planId.toString(), e.target.value); + localStorage.setItem("notes", JSON.stringify(notesObject)); console.log("New notes: ", e.target.value); }; useEffect(() => { if (!planId) return; - - const storedNotes = localStorage.getItem(planId.toString()); + const storedNotes = localStorage.getItem("notes"); + const notesObject = storedNotes ? JSON.parse(storedNotes) : {}; if (storedNotes) { - setNotes(storedNotes); + setNotes(notesObject[planId]); } }, [planId]); @@ -434,30 +439,36 @@ const SidebarContainer: React.FC> = ({ {children} - - - - sandbox logo + {planId && ( + + + + sandbox logo + + Sandbox Area {planId} + + - Sandbox Area {planId} + Notes - - - Notes - - - - + + + + )} ); };