"use client" import { useState, useCallback, useEffect, useRef } from "react" import { Dialog, DialogContent, DialogTitle } from "@repo/ui/components/dialog" import { cn } from "@lib/utils" import { dmSansClassName } from "@/lib/fonts" import { Logo } from "@ui/assets/Logo" import { Minimize2, Plus, Loader2 } from "lucide-react" import { useAuth } from "@lib/auth-context" import { TextEditor } from "./text-editor" import { useProject } from "@/stores" import { useQuickNoteDraft } from "@/stores/quick-note-draft" interface FullscreenNoteModalProps { isOpen: boolean onClose: () => void initialContent?: string onSave: (content: string) => void isSaving?: boolean } export function FullscreenNoteModal({ isOpen, onClose, initialContent = "", onSave, isSaving = false, }: FullscreenNoteModalProps) { const { user } = useAuth() const { selectedProject } = useProject() const { setDraft } = useQuickNoteDraft(selectedProject) const [content, setContent] = useState(initialContent) const contentRef = useRef(content) useEffect(() => { contentRef.current = content }, [content]) useEffect(() => { if (isOpen) { setContent(initialContent) } }, [isOpen, initialContent]) const displayName = user?.displayUsername || (typeof window !== "undefined" && localStorage.getItem("username")) || (typeof window !== "undefined" && localStorage.getItem("userName")) || "" const userName = displayName ? `${displayName.split(" ")[0]}'s` : "My" const handleSave = useCallback(() => { const currentContent = contentRef.current if (currentContent.trim() && !isSaving) { onSave(currentContent) } }, [isSaving, onSave]) const handleContentChange = useCallback( (newContent: string) => { console.log("handleContentChange", newContent) setContent(newContent) setDraft(newContent) }, [setDraft], ) const canSave = content.trim().length > 0 && !isSaving useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Escape" && isOpen) { e.preventDefault() onClose() } } if (isOpen) { document.addEventListener("keydown", handleKeyDown) } return () => { document.removeEventListener("keydown", handleKeyDown) } }, [isOpen, onClose]) return ( !open && onClose()}> New Note
{userName && (

{userName}

supermemory

)}
ESC
) }