diff --git a/apps/web/src/ui/app/AppShell.tsx b/apps/web/src/ui/app/AppShell.tsx index 439c09e..36c808d 100644 --- a/apps/web/src/ui/app/AppShell.tsx +++ b/apps/web/src/ui/app/AppShell.tsx @@ -1914,6 +1914,8 @@ function Memo({ >({}); const [lastSavedAt, setLastSavedAt] = useState(null); const [saveError, setSaveError] = useState(null); + const [addingSection, setAddingSection] = useState(false); + const [deletingSectionId, setDeletingSectionId] = useState(null); const saveTimers = useRef>({}); const sections = sectionsDraft; const activeIndex = Math.max( @@ -2123,6 +2125,64 @@ function Memo({ else setSaveError(result.error.message); } + async function addSection(afterSectionId?: string) { + if (!company) return; + setAddingSection(true); + try { + const index = afterSectionId + ? sections.findIndex((s) => s.id === afterSectionId) + : sections.length - 1; + const title = `New Section`; + const result = await rpc.call("memo.addSection", { + companyId: company.id, + title, + afterSectionId, + }); + if (result.ok) { + const newSection = result.data.section; + setSectionsDraft((prev) => { + const next = [...prev]; + next.splice(index + 1, 0, newSection); + return next; + }); + setActiveSectionId(newSection.id); + setSaveStateBySection((prev) => ({ ...prev, [newSection.id]: "saved" })); + addToast({ type: "success", title: "Section added", desc: `"${title}" added to memo` }); + } else { + addToast({ type: "error", title: "Could not add section", desc: result.error.message }); + } + } finally { + setAddingSection(false); + } + } + + async function deleteSection(sectionId: string) { + if (!company) return; + if (sections.length <= 1) { + addToast({ type: "warning", title: "Cannot delete", desc: "A memo must have at least one section." }); + return; + } + setDeletingSectionId(sectionId); + try { + const result = await rpc.call("memo.deleteSection", { + companyId: company.id, + sectionId, + }); + if (result.ok) { + setSectionsDraft((prev) => prev.filter((s) => s.id !== sectionId)); + if (activeSectionId === sectionId) { + const remaining = sections.filter((s) => s.id !== sectionId); + setActiveSectionId(remaining[0]?.id ?? ""); + } + addToast({ type: "success", title: "Section deleted" }); + } else { + addToast({ type: "error", title: "Could not delete section", desc: result.error.message }); + } + } finally { + setDeletingSectionId(null); + } + } + const activeCitations = memo.citations.filter( (c) => c.sectionId === activeSectionId, ); @@ -2176,22 +2236,43 @@ function Memo({ {!outlineCollapsed && sections.map((s, i) => ( - + {s.title} + {s.primaryAgent && ( + + [{s.primaryAgent}] + + )} + + + ))} + {!outlineCollapsed && ( + + )}
@@ -2309,6 +2390,13 @@ function Memo({ )} ))} +
{rightPanelCollapsed ? (