import { FeatherIcon, LockKeyIcon } from "@phosphor-icons/react"; import { useState } from "react"; import { useNavigate } from "react-router-dom"; import Logo from "../components/Logo"; import { DrawerSection } from "../components/ui/DrawerSection"; import { LetterItem } from "../components/ui/LetterItem"; import { PATHS } from "../config/routes"; import { useAuth } from "../hooks/useAuth"; import { useLetters } from "../hooks/useLetters"; export default function Drawer() { const { user, logout, unlock } = useAuth(); const [openSection, setOpenSection] = useState(null); const navigate = useNavigate(); const { drafts, kept, sent, vault, loading, isAuthRequired } = useLetters(); if (!user) return null; const toggleSection = (id: string) => setOpenSection(openSection === id ? null : id); return (
{isAuthRequired && (

Authentication Required

We need your passkey to open your letters

P.S. We don't validate your input at the moment.

) => { e.preventDefault(); const formData = new FormData(e.currentTarget); const password = formData.get("password") as string; if (!password) return; unlock(password); }} >
)}
Personal Archive
Welcome Back{" "} {user.full_name}
{loading ? (
Opening your cabinet...
) : ( <> toggleSection("drafts")} > {drafts.map((draft) => ( ))} toggleSection("kept")} > {kept.map((letter) => ( ))} toggleSection("sent")} > {sent.map((letter) => ( ))} {sent.length === 0 && (

This drawer remains silent

)}
toggleSection("vault")} > {vault.map((letter) => ( ))} )}
); }