Replace the FastAPI/HTMX prototype with a Node/Hono session proxy and a React 19/Vite SPA. Mail (conversation view, search operators, labels, sanitised HTML, privacy image proxy, invites, undo send, templates), calendar (month/week/day/agenda, invites, free/busy, categories, context menus), contacts (JSContact, groups, vCard), files, Sieve filter builder (incl. filter-from-message with retroactive apply), vacation, identities with default + Reply-To, PWA/mobile layout, push via SSE, in-memory mock Stalwart for dev, Docker + CI.
65 lines
2.6 KiB
TypeScript
65 lines
2.6 KiB
TypeScript
import { useMemo, useState } from "react";
|
|
import { Folder, Inbox } from "lucide-react";
|
|
import { useMail } from "@/store/mail";
|
|
import { Dialog } from "@/ui/dialog";
|
|
import type { Id, Mailbox } from "@/jmap/types";
|
|
|
|
export function MailboxPicker({ title, onClose, onPick, exclude }: { title: string; onClose: () => void; onPick: (id: Id) => void; exclude?: Id[] }) {
|
|
const mailboxes = useMail((s) => s.mailboxes);
|
|
const mailboxPath = useMail((s) => s.mailboxPath);
|
|
const [q, setQ] = useState("");
|
|
const [active, setActive] = useState(0);
|
|
const list = useMemo(() => {
|
|
const all = Object.values(mailboxes)
|
|
.filter((m) => !exclude?.includes(m.id) && m.myRights.mayAddItems)
|
|
.map((m) => ({ m, path: mailboxPath(m.id) }))
|
|
.sort((a, b) => (a.m.role === "inbox" ? -1 : b.m.role === "inbox" ? 1 : a.path.localeCompare(b.path)));
|
|
const ql = q.trim().toLowerCase();
|
|
return ql ? all.filter((x) => x.path.toLowerCase().includes(ql)) : all;
|
|
}, [mailboxes, mailboxPath, q, exclude]);
|
|
|
|
return (
|
|
<Dialog open onClose={onClose} title={title} size="sm">
|
|
<input
|
|
className="input"
|
|
autoFocus
|
|
placeholder="Type a folder name…"
|
|
value={q}
|
|
onChange={(e) => {
|
|
setQ(e.target.value);
|
|
setActive(0);
|
|
}}
|
|
onKeyDown={(e) => {
|
|
if (e.key === "ArrowDown") {
|
|
e.preventDefault();
|
|
setActive((a) => Math.min(list.length - 1, a + 1));
|
|
} else if (e.key === "ArrowUp") {
|
|
e.preventDefault();
|
|
setActive((a) => Math.max(0, a - 1));
|
|
} else if (e.key === "Enter") {
|
|
e.preventDefault();
|
|
const m = list[active]?.m;
|
|
if (m) onPick(m.id);
|
|
}
|
|
}}
|
|
/>
|
|
<div style={{ maxHeight: 360, overflowY: "auto", marginTop: 8 }} role="listbox">
|
|
{list.map(({ m, path }, i) => (
|
|
<PickerRow key={m.id} m={m} path={path} active={i === active} onClick={() => onPick(m.id)} onHover={() => setActive(i)} />
|
|
))}
|
|
{!list.length && <div className="empty" style={{ padding: 24 }}>No matching folders</div>}
|
|
</div>
|
|
</Dialog>
|
|
);
|
|
}
|
|
|
|
function PickerRow({ m, path, active, onClick, onHover }: { m: Mailbox; path: string; active: boolean; onClick: () => void; onHover: () => void }) {
|
|
return (
|
|
<button className={`menu-item ${active ? "active" : ""}`} onClick={onClick} onMouseEnter={onHover} role="option" aria-selected={active}>
|
|
{m.role === "inbox" ? <Inbox size={16} /> : <Folder size={16} />}
|
|
<span className="grow truncate">{path}</span>
|
|
<span className="menu-kbd">{m.totalEmails}</span>
|
|
</button>
|
|
);
|
|
}
|