diff --git a/apps/web/components/memories-grid.tsx b/apps/web/components/memories-grid.tsx index d2f93d544..0fd451627 100644 --- a/apps/web/components/memories-grid.tsx +++ b/apps/web/components/memories-grid.tsx @@ -542,13 +542,13 @@ export function MemoriesGrid({ {!isEmpty && !isSelectionMode && (
-
+
-
+
{/* View mode toggle — segmented control */}
void @@ -18,28 +19,23 @@ export function QuickNoteCard({ onMaximize, isSaving = false, }: QuickNoteCardProps) { - const textareaRef = useRef(null) + const [isExpanded, setIsExpanded] = useState(false) const { selectedProject } = useProject() const { draft, setDraft } = useQuickNoteDraft(selectedProject) + const draftRef = useRef(draft) + draftRef.current = draft - const handleChange = useCallback( - (e: React.ChangeEvent) => { - setDraft(e.target.value) - }, + const handleContentChange = useCallback( + (content: string) => setDraft(content), [setDraft], ) - const handleKeyDown = useCallback( - (e: React.KeyboardEvent) => { - if ((e.metaKey || e.ctrlKey) && e.key === "Enter") { - e.preventDefault() - if (draft.trim() && !isSaving) { - onSave(draft) - } - } - }, - [draft, isSaving, onSave], - ) + const handleEditorSubmit = useCallback(() => { + const currentDraft = draftRef.current + if (currentDraft.trim() && !isSaving) { + onSave(currentDraft) + } + }, [isSaving, onSave]) const handleSaveClick = useCallback(() => { if (draft.trim() && !isSaving) { @@ -51,109 +47,171 @@ export function QuickNoteCard({ onMaximize(draft) }, [draft, onMaximize]) + const handleBlurCapture = useCallback( + (e: React.FocusEvent) => { + if (e.currentTarget.contains(e.relatedTarget as Node | null)) return + setIsExpanded(false) + }, + [], + ) + + const handleBackdropPointerDown = useCallback(() => { + const activeElement = document.activeElement + if (activeElement instanceof HTMLElement) { + activeElement.blur() + } + setIsExpanded(false) + }, []) + + useEffect(() => { + if (!isExpanded) return + + const handleKeyDown = (event: KeyboardEvent) => { + if (event.key !== "Escape") return + const activeElement = document.activeElement + if (activeElement instanceof HTMLElement) { + activeElement.blur() + } + setIsExpanded(false) + } + + window.addEventListener("keydown", handleKeyDown) + return () => window.removeEventListener("keydown", handleKeyDown) + }, [isExpanded]) + const canSave = draft.trim().length > 0 && !isSaving + const hasDraft = draft.trim().length > 0 + const editorHeight = isExpanded + ? "min-h-[min(58dvh,520px)] sm:min-h-[min(54vh,560px)]" + : hasDraft + ? "min-h-[188px]" + : "min-h-[120px]" return ( -
+ <> + {isExpanded && ( +
+ )}
- - -