Skip to content

Email for professionals and teams

improve UI

Hieu Nguyen (Jack)516e2a1d0959
diff --git a/src/app/(dashboard)/inbox/[messageId]/page.tsx b/src/app/(dashboard)/inbox/[messageId]/page.tsx
index 29a13fb..45e4f2b 100644
--- a/src/app/(dashboard)/inbox/[messageId]/page.tsx
+++ b/src/app/(dashboard)/inbox/[messageId]/page.tsx
@@ -1,9 +1,8 @@
"use client";
-import Link from "next/link";
-import { useParams, usePathname } from "next/navigation";
+import { useParams } from "next/navigation";
import { useEffect, useState } from "react";
-import { ArrowLeft, Cloud, Columns2, ExternalLink, List, Rows2 } from "lucide-react";
+import { Cloud, ExternalLink } from "lucide-react";
import dayjs from "dayjs";
import { MarkAsRead } from "@/components/mark-read";
import { useSelectedMailbox } from "@/components/mailbox-provider";
@@ -16,14 +15,13 @@ import { MessageDetailSkeleton } from "@/components/page-skeletons";
import { usePageLoading } from "@/components/page-loading";
import { PreviousMessage } from "@/components/previous-message";
import { ConversationThread } from "@/components/messages/conversation-thread";
+import { MessageDetailNavigation } from "@/components/messages/message-detail-navigation";
+import { MessageReadingHeaderButton } from "@/components/messages/message-reading-header-button";
import { QuotedEmailToggle } from "@/components/messages/quoted-email-toggle";
import { ThreadMessageActions } from "@/components/messages/thread-message-actions";
-import { SpamScoreDetails } from "@/components/messages/spam-score-details";
import { useMessageThread } from "@/components/messages/use-message-thread";
import { useLatestMessagesFirst } from "@/components/messages/use-latest-messages-first";
import { useMessageListVisibility } from "@/components/messages/message-list-visibility";
-import { Tooltip } from "@/components/ui/tooltip";
-import { getMessageBackHref } from "@/components/message-actions/utils";
import { getEmailAddress, getEmailDisplayName, splitEmailAddressList } from "@/lib/email/address";
import type { MessageAttachment, MessageDetailResponse } from "./types";
import {
@@ -40,10 +38,10 @@ import { sanitizeEmailHtml } from "./email-html-sanitizer";
import { collapseQuotedEmailHtml } from "./quote-collapse-utils";
import clsx from "clsx";
import { useAssistantOpen } from "@/components/agent/assistant-open-state";
+import { useMessageContentScroll } from "./use-message-content-scroll";
export default function MessageDetailPage() {
const params = useParams<{ messageId: string }>();
- const pathname = usePathname();
const { selectedMailbox, mailboxes } = useSelectedMailbox();
const messageId = params.messageId;
const [data, setData] = useState<MessageDetailResponse | null>(null);
@@ -52,11 +50,12 @@ export default function MessageDetailPage() {
useState<MessageAttachment | null>(null);
const [threadExpanded, setThreadExpanded] = useState(false);
const [latestMessagesFirst] = useLatestMessagesFirst();
- const { visible: messageListVisible, toggle: toggleMessageList } = useMessageListVisibility();
+ const { visible: messageListVisible } = useMessageListVisibility();
usePageLoading(loading);
const thread = useMessageThread(messageId, data?.message?.threadId);
const assistantVisible = useAssistantOpen();
const isAnyPanelVisible = messageListVisible || assistantVisible;
+ const { scrollRef, scrolled, handleScroll } = useMessageContentScroll(messageId, loading);
useEffect(() => {
let cancelled = false;
@@ -146,9 +145,9 @@ export default function MessageDetailPage() {
);
return (<>
- <div className="flex py-2 h-14 items-center justify-between px-2 border-b border-neutral-200 sticky top-0 bg-white z-40 gap-4">
- <Tooltip label={assistantVisible ? null : messageListVisible ? "Hide email list" : "Show email list"} className="hidden lg:inline-flex"><button type="button" className={clsx(assistantVisible ? "opacity-40" : messageListVisible ? "" : "opacity-60 hover:opacity-100", !assistantVisible && "hover:bg-neutral-100 hover:text-neutral-900", "relative z-10 shrink-0 rounded-full p-2 text-neutral-600 duration-200")} onClick={toggleMessageList} disabled={assistantVisible} aria-label={messageListVisible ? "Hide email list" : "Show email list"} aria-pressed={messageListVisible}><Columns2 size={18} /></button></Tooltip>
- <div className="min-w-0 flex-1" />
+ <div className={clsx("flex py-2 h-12 items-center px-2 border-b sticky top-0 bg-white z-40 gap-3", scrolled ? "border-neutral-200" : "border-transparent")}>
+ <MessageReadingHeaderButton assistantVisible={assistantVisible} />
+ {/* <div className="min-w-0 flex-1" /> */}
{/* <div className="flex items-center flex-row gap-6">
<Link
href={getMessageBackHref(message.direction, message.status)}
@@ -173,12 +172,13 @@ export default function MessageDetailPage() {
messageMeta={message}
bodyHtml={body?.htmlBody}
/>
+ <MessageDetailNavigation messageId={message.id} unread={message.direction === "inbound" && !message.read} />
</div>
- <div className="h-full overflow-y-auto overscroll-contain scrollbar-gutter-stable">
+ <div ref={scrollRef} onScroll={handleScroll} className="h-full overflow-y-auto overscroll-contain scrollbar-gutter-stable flex-1 min-h-0">
{!message.read && <MarkAsRead messageId={message.id} />}
- <h1 className={clsx(!isAnyPanelVisible ? "pl-16" : "pl-10", "pr-6 pb-2 pt-4 text-2xl font-medium text-neutral-900")} title={message.subject ?? "(no subject)"}>
+ <h1 className={clsx(!isAnyPanelVisible ? "pl-16" : "pl-10", "pr-6 pb-2 pt-2 text-2xl text-neutral-900")} title={message.subject ?? "(no subject)"}>
{message.subject ?? "(no subject)"}
</h1>
{/* <div className="px-6">
diff --git a/src/app/(dashboard)/inbox/[messageId]/use-message-content-scroll.ts b/src/app/(dashboard)/inbox/[messageId]/use-message-content-scroll.ts
new file mode 100644
index 0000000..b3ec54f
--- /dev/null
+++ b/src/app/(dashboard)/inbox/[messageId]/use-message-content-scroll.ts
@@ -0,0 +1,21 @@
+import { useEffect, useRef, useState } from "react";
+
+export function useMessageContentScroll(messageId: string, loading: boolean) {
+ const scrollRef = useRef<HTMLDivElement>(null);
+ const [scrolled, setScrolled] = useState(false);
+
+ useEffect(() => {
+ setScrolled((scrollRef.current?.scrollTop ?? 0) > 0);
+ }, [messageId, loading]);
+
+ useEffect(() => {
+ if (scrollRef.current) scrollRef.current.scrollTop = 0;
+ setScrolled(false);
+ }, [messageId]);
+
+ function handleScroll() {
+ setScrolled((scrollRef.current?.scrollTop ?? 0) > 0);
+ }
+
+ return { scrollRef, scrolled, handleScroll };
+}
diff --git a/src/app/(settings)/settings/inbox/page.tsx b/src/app/(settings)/settings/inbox/page.tsx
index 1c6f1a5..ceb4422 100644
--- a/src/app/(settings)/settings/inbox/page.tsx
+++ b/src/app/(settings)/settings/inbox/page.tsx
@@ -1,4 +1,5 @@
import { InboxThreadingSettings } from "@/components/settings/inbox-threading-settings";
+import { InboxReadingLayoutSettings } from "@/components/settings/inbox-reading-layout-settings";
import { InboxShortcutsSettings } from "@/components/settings/inbox-shortcuts-settings";
import { MailboxAutoReplyForm } from "@/components/settings/mailbox-auto-reply-form";
import { SpamFilterSettings } from "@/components/settings/spam-filter-settings";
@@ -9,51 +10,62 @@ export default function SettingsInboxPage() {
<div className="space-y-8 py-4">
<section className="space-y-4">
<div>
- <h2 className="text-xl font-semibold text-neutral-900">Notifications</h2>
- <p className="mt-1 text-sm text-neutral-500">Choose how you hear about new email.</p>
+ <h2 className="text-xl font-semibold text-neutral-900">Inbox experience</h2>
+ <p className="mt-1 text-sm text-neutral-500">Choose how you read and interact with email.</p>
</div>
- <div className="rounded-3xl bg-white p-6">
- <BrowserNotificationSettings />
+ <div className="divide-y divide-neutral-100 rounded-3xl bg-white p-6">
+ <div className="py-6 first:pt-0 last:pb-0">
+ <div className="mb-4">
+ <h3 className="text-base font-semibold text-neutral-900">Reading layout</h3>
+ <p className="mt-1 text-sm text-neutral-500">Choose how open emails appear.</p>
+ </div>
+ <InboxReadingLayoutSettings />
+ </div>
+ <div className="py-6 first:pt-0 last:pb-0">
+ <div className="mb-4">
+ <h3 className="text-base font-semibold text-neutral-900">Threading</h3>
+ <p className="mt-1 text-sm text-neutral-500">Choose how emails are organized in your inbox.</p>
+ </div>
+ <InboxThreadingSettings />
+ </div>
+ <div className="py-6 first:pt-0 last:pb-0">
+ <div className="mb-4">
+ <h3 className="text-base font-semibold text-neutral-900">Shortcuts</h3>
+ <p className="mt-1 text-sm text-neutral-500">Choose whether keyboard shortcuts are active.</p>
+ </div>
+ <InboxShortcutsSettings />
+ </div>
+ <div className="py-6 first:pt-0 last:pb-0">
+ <div className="mb-4">
+ <h3 className="text-base font-semibold text-neutral-900">Notifications</h3>
+ <p className="mt-1 text-sm text-neutral-500">Choose how you hear about new email.</p>
+ </div>
+ <BrowserNotificationSettings />
+ </div>
</div>
</section>
<section className="space-y-4">
<div>
- <h2 className="text-xl font-semibold text-neutral-900">Spam protection</h2>
- <p className="mt-1 text-sm text-neutral-500">Control local spam analysis for incoming messages.</p>
+ <h2 className="text-xl font-semibold text-neutral-900">Message handling</h2>
+ <p className="mt-1 text-sm text-neutral-500">Manage spam protection and automatic replies.</p>
</div>
- <div className="rounded-3xl bg-white p-6">
- <SpamFilterSettings />
- </div>
- </section>
- <section className="space-y-4">
- <div>
- <h2 className="text-xl font-semibold text-neutral-900">Threading</h2>
- <p className="mt-1 text-sm text-neutral-500">Choose how emails are organized in your inbox.</p>
- </div>
- <div className="rounded-3xl bg-white p-6">
- <InboxThreadingSettings />
- </div>
- </section>
-
- <section className="space-y-4">
- <div>
- <h2 className="text-xl font-semibold text-neutral-900">Shortcuts</h2>
- <p className="mt-1 text-sm text-neutral-500">Choose whether keyboard shortcuts are active.</p>
- </div>
- <div className="rounded-3xl bg-white p-6">
- <InboxShortcutsSettings />
- </div>
- </section>
-
- <section className="space-y-4">
- <div>
- <h2 className="text-xl font-semibold text-neutral-900">Automatic response</h2>
- <p className="mt-1 text-sm text-neutral-500">
- Configure the subject and message for the inbox currently selected above.
- </p>
- </div>
- <div className="rounded-3xl bg-white p-6">
- <MailboxAutoReplyForm />
+ <div className="divide-y divide-neutral-100 rounded-3xl bg-white p-6">
+ <div className="py-6 first:pt-0 last:pb-0">
+ <div className="mb-4">
+ <h3 className="text-base font-semibold text-neutral-900">Spam protection</h3>
+ <p className="mt-1 text-sm text-neutral-500">Control local spam analysis for incoming messages.</p>
+ </div>
+ <SpamFilterSettings />
+ </div>
+ <div className="py-6 first:pt-0 last:pb-0">
+ <div className="mb-4">
+ <h3 className="text-base font-semibold text-neutral-900">Automatic response</h3>
+ <p className="mt-1 text-sm text-neutral-500">
+ Configure the subject and message for the inbox currently selected above.
+ </p>
+ </div>
+ <MailboxAutoReplyForm />
+ </div>
</div>
</section>
</div>
diff --git a/src/app/api/messages/navigation/route.ts b/src/app/api/messages/navigation/route.ts
new file mode 100644
index 0000000..4bd0ba0
--- /dev/null
+++ b/src/app/api/messages/navigation/route.ts
@@ -0,0 +1,85 @@
+import { NextResponse } from "next/server";
+import { and, desc, eq, gt, inArray, isNull, lte, or } from "drizzle-orm";
+import type { SQL } from "drizzle-orm";
+import { getDb } from "@/db";
+import { messages } from "@/db/schema";
+import { getCurrentUser } from "@/lib/auth/cookies";
+import { getEnv } from "@/lib/cloudflare";
+import { getMailboxAccessLevel, listAccessibleMailboxIds } from "@/lib/mailboxes/access";
+import type { MessageFolder } from "@/hooks/types";
+import type { MessageNavigationEntry } from "./types";
+
+const folders: MessageFolder[] = ["inbox", "starred", "snoozed", "sent", "archived", "spam", "trash"];
+
+export async function GET(request: Request) {
+ const env = getEnv();
+ const user = await getCurrentUser(env, request);
+ if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
+
+ const params = new URL(request.url).searchParams;
+ const folder = params.get("folder") as MessageFolder | null;
+ if (!folder || !folders.includes(folder)) {
+ return NextResponse.json({ error: "Invalid folder" }, { status: 400 });
+ }
+
+ const mailboxId = params.get("mailboxId");
+ const folderId = params.get("folderId");
+ const grouped = params.get("group") === "thread";
+ const db = getDb(env);
+ const conditions: SQL[] = [];
+ if (mailboxId) {
+ const access = await getMailboxAccessLevel(db, user, mailboxId);
+ if (!access?.canRead) return NextResponse.json({ error: "Mailbox not found" }, { status: 404 });
+ conditions.push(eq(messages.mailboxId, mailboxId));
+ } else {
+ const accessibleIds = await listAccessibleMailboxIds(db, user);
+ conditions.push(accessibleIds.length > 0
+ ? inArray(messages.mailboxId, accessibleIds)
+ : eq(messages.userId, user.id));
+ }
+
+ if (folder === "inbox") {
+ conditions.push(eq(messages.direction, "inbound"));
+ conditions.push(eq(messages.status, "received"));
+ if (!folderId) {
+ conditions.push(isNull(messages.folderId));
+ conditions.push(or(isNull(messages.snoozedUntil), lte(messages.snoozedUntil, new Date()))!);
+ }
+ } else if (folder === "starred") {
+ conditions.push(eq(messages.starred, true));
+ } else if (folder === "snoozed") {
+ conditions.push(eq(messages.status, "received"));
+ conditions.push(isNull(messages.folderId));
+ conditions.push(gt(messages.snoozedUntil, new Date()));
+ } else if (folder === "sent") {
+ conditions.push(eq(messages.direction, "outbound"));
+ conditions.push(eq(messages.status, "sent"));
+ } else {
+ conditions.push(eq(messages.status, folder));
+ }
+ if (folderId) conditions.push(eq(messages.folderId, folderId));
+
+ const rows = await db.select({
+ id: messages.id,
+ read: messages.read,
+ direction: messages.direction,
+ threadId: messages.threadId,
+ }).from(messages).where(and(...conditions)).orderBy(desc(messages.createdAt), desc(messages.id));
+
+ const entries: MessageNavigationEntry[] = [];
+ if (grouped) {
+ const byThread = new Map<string, MessageNavigationEntry>();
+ for (const row of rows) {
+ const key = row.threadId ?? row.id;
+ const unread = row.direction === "inbound" && !row.read;
+ const existing = byThread.get(key);
+ if (existing) existing.unread ||= unread;
+ else byThread.set(key, { id: row.id, unread });
+ }
+ entries.push(...byThread.values());
+ } else {
+ entries.push(...rows.map((row) => ({ id: row.id, unread: row.direction === "inbound" && !row.read })));
+ }
+
+ return NextResponse.json({ messages: entries });
+}
diff --git a/src/app/api/messages/navigation/types.d.ts b/src/app/api/messages/navigation/types.d.ts
new file mode 100644
index 0000000..4060e4c
--- /dev/null
+++ b/src/app/api/messages/navigation/types.d.ts
@@ -0,0 +1,8 @@
+export type MessageNavigationEntry = {
+ id: string;
+ unread: boolean;
+};
+
+export type MessageNavigationResponse = {
+ messages: MessageNavigationEntry[];
+};
diff --git a/src/app/home-account-menu.tsx b/src/app/home-account-menu.tsx
new file mode 100644
index 0000000..b2abb7c
--- /dev/null
+++ b/src/app/home-account-menu.tsx
@@ -0,0 +1,13 @@
+"use client";
+
+import { MailboxProvider } from "@/components/mailbox-provider";
+import { MailboxSelector } from "@/components/mailbox-selector";
+import type { HomeAccountMenuProps } from "./types";
+
+export function HomeAccountMenu({ user }: HomeAccountMenuProps) {
+ return (
+ <MailboxProvider>
+ <MailboxSelector initialUser={user} />
+ </MailboxProvider>
+ );
+}
diff --git a/src/app/home-auth.tsx b/src/app/home-auth.tsx
new file mode 100644
index 0000000..16c4775
--- /dev/null
+++ b/src/app/home-auth.tsx
@@ -0,0 +1,31 @@
+"use client";
+
+import { createContext, useContext, useEffect, useState } from "react";
+import { authFetch } from "@/lib/auth/client";
+import type { MailboxSelectorUser } from "@/components/mailbox-selector-types";
+import type { HomeAuthProviderProps, HomeAuthResponse } from "./types";
+
+const HomeAuthContext = createContext<MailboxSelectorUser | null>(null);
+
+export function HomeAuthProvider({ children }: HomeAuthProviderProps) {
+ const [user, setUser] = useState<MailboxSelectorUser | null>(null);
+
+ useEffect(() => {
+ let cancelled = false;
+ void authFetch("/api/auth/me", { redirectOnUnauthorized: false })
+ .then(async (response) => response.ok ? await response.json() as HomeAuthResponse : null)
+ .then((data) => {
+ if (!cancelled) setUser(data?.user ?? null);
+ })
+ .catch(() => {
+ if (!cancelled) setUser(null);
+ });
+ return () => { cancelled = true; };
+ }, []);
+
+ return <HomeAuthContext.Provider value={user}>{children}</HomeAuthContext.Provider>;
+}
+
+export function useHomeAuth() {
+ return useContext(HomeAuthContext);
+}
diff --git a/src/app/home-header-actions.tsx b/src/app/home-header-actions.tsx
new file mode 100644
index 0000000..d20131d
--- /dev/null
+++ b/src/app/home-header-actions.tsx
@@ -0,0 +1,22 @@
+"use client";
+
+import Link from "next/link";
+import { Button } from "@/components/ui/button";
+import { getHomeActions } from "./utils";
+import { HomeAccountMenu } from "./home-account-menu";
+import { useHomeAuth } from "./home-auth";
+
+export function HomeHeaderActions() {
+ const user = useHomeAuth();
+ if (user) return <HomeAccountMenu user={user} />;
+
+ return (
+ <>
+ {getHomeActions(false).map((action) => (
+ <Button key={action.href} variant={action.variant} asChild>
+ <Link href={action.href}>{action.label}</Link>
+ </Button>
+ ))}
+ </>
+ );
+}
diff --git a/src/app/home-hero-actions.tsx b/src/app/home-hero-actions.tsx
new file mode 100644
index 0000000..17a3bc7
--- /dev/null
+++ b/src/app/home-hero-actions.tsx
@@ -0,0 +1,26 @@
+"use client";
+
+import Link from "next/link";
+import { ArrowRight } from "lucide-react";
+import { Button } from "@/components/ui/button";
+import { useHomeAuth } from "./home-auth";
+
+export function HomeHeroActions() {
+ const hasUser = !!useHomeAuth();
+
+ return (
+ <div className="mt-8 flex flex-col gap-3 sm:flex-row">
+ <Button size="lg" asChild className="rounded-full px-6">
+ <Link href={hasUser ? "/inbox" : "/setup"}>
+ {hasUser ? "Open dashboard" : "Create account"}
+ <ArrowRight className="h-4 w-4" />
+ </Link>
+ </Button>
+ <Button size="lg" variant="outline" asChild className="rounded-full border-neutral-200 bg-white px-6">
+ <Link href={hasUser ? "/inbox" : "/login"}>
+ {hasUser ? "View inbox" : "Log in"}
+ </Link>
+ </Button>
+ </div>
+ );
+}
diff --git a/src/app/home-server-utils.ts b/src/app/home-server-utils.ts
new file mode 100644
index 0000000..51b6395
--- /dev/null
+++ b/src/app/home-server-utils.ts
@@ -0,0 +1,12 @@
+import { cache } from "react";
+import { getBranding } from "@/lib/branding/service";
+import { getEnv } from "@/lib/cloudflare";
+import { DEFAULT_BRANDING } from "@/components/branding-provider-utils";
+
+export const getHomeBranding = cache(async () => {
+ try {
+ return await getBranding(getEnv());
+ } catch {
+ return DEFAULT_BRANDING;
+ }
+});
diff --git a/src/app/page.tsx b/src/app/page.tsx
index ca720ea..d8a8ad8 100644
--- a/src/app/page.tsx
+++ b/src/app/page.tsx
@@ -1,45 +1,35 @@
-"use client";
-
+import type { Metadata } from "next";
import Link from "next/link";
-import { useEffect, useState } from "react";
-import { Button } from "@/components/ui/button";
-import { authFetch, getClientSessionToken } from "@/lib/auth/client";
-import { getHomeActions, heroMessages, sidebarItems } from "./utils";
-import { ArrowRight, Inbox, Mail, Search, ShieldCheck } from "lucide-react";
-import { useBranding } from "@/components/branding-provider";
-
-export default function HomePage() {
- const branding = useBranding();
- const [hasUser, setHasUser] = useState(false);
-
- useEffect(() => {
- let cancelled = false;
- if (!getClientSessionToken()) return;
+import { heroMessages, sidebarItems } from "./utils";
+import { Inbox, Mail, Search, ShieldCheck } from "lucide-react";
+import { getHomeBranding } from "./home-server-utils";
+import { HomeAuthProvider } from "./home-auth";
+import { HomeHeaderActions } from "./home-header-actions";
+import { HomeHeroActions } from "./home-hero-actions";
- authFetch("/api/auth/me", { redirectOnUnauthorized: false })
- .then((response) => {
- if (!cancelled) setHasUser(response.ok);
- })
- .catch(() => {
- if (!cancelled) setHasUser(false);
- });
+export const dynamic = "force-dynamic";
- return () => {
- cancelled = true;
- };
- }, []);
+export async function generateMetadata(): Promise<Metadata> {
+ const branding = await getHomeBranding();
+ return {
+ title: branding.appName,
+ icons: { icon: branding.hasCustomIcon ? "/api/branding/icon" : "/icon-96.png" },
+ };
+}
- const actions = getHomeActions(hasUser);
+export default async function HomePage() {
+ const branding = await getHomeBranding();
return (
+ <HomeAuthProvider>
<div className="min-h-dvh bg-[#f6f8fc] text-neutral-900">
<header className="mx-auto flex h-16 w-full max-w-7xl items-center justify-between px-4 sm:px-6 lg:px-8">
<Link
href="/"
className="flex items-center gap-3"
- aria-label="Email Platform home"
+ aria-label={`${branding.appName} home`}
>
- <img src={branding.iconUrl} height={32} width={32} alt="" />
+ <img src={branding.hasCustomIcon ? "/api/branding/icon" : "/icon-96.png"} height={32} width={32} alt="" />
<span className="text-base font-semibold tracking-tight">
{branding.appName}
</span>
@@ -54,11 +44,7 @@ export default function HomePage() {
</nav> */}
<div className="flex items-center gap-2">
- {actions.map((action) => (
- <Button key={action.href} variant={action.variant} asChild>
- <Link href={action.href}>{action.label}</Link>
- </Button>
- ))}
+ <HomeHeaderActions />
</div>
</header>
@@ -76,24 +62,7 @@ export default function HomePage() {
Add domains, route inbound mail, send through API keys, and manage
your mailboxes from one quiet workspace built around the message list.
</p>
- <div className="mt-8 flex flex-col gap-3 sm:flex-row">
- <Button size="lg" asChild className="rounded-full px-6">
- <Link href={actions.at(-1)?.href ?? "/setup"}>
- {hasUser ? "Open dashboard" : "Create account"}
- <ArrowRight className="h-4 w-4" />
- </Link>
- </Button>
- <Button
- size="lg"
- variant="outline"
- asChild
- className="rounded-full border-neutral-200 bg-white px-6"
- >
- <Link href={hasUser ? "/inbox" : "/login"}>
- {hasUser ? "View inbox" : "Log in"}
- </Link>
- </Button>
- </div>
+ <HomeHeroActions />
</div>
<div className="relative min-h-[520px] overflow-hidden rounded-[2rem] border border-white bg-white shadow-[0_24px_70px_-45px_rgba(30,64,175,0.55)]">
@@ -221,5 +190,6 @@ export default function HomePage() {
</section> */}
</main>
</div>
+ </HomeAuthProvider>
);
}
diff --git a/src/app/types.d.ts b/src/app/types.d.ts
index bf1566e..1f1e50e 100644
--- a/src/app/types.d.ts
+++ b/src/app/types.d.ts
@@ -1,5 +1,19 @@
import type { LucideIcon } from "lucide-react";
import type { ButtonProps } from "@/components/ui/button";
+import type { MailboxSelectorUser } from "@/components/mailbox-selector-types";
+import type { ReactNode } from "react";
+
+export type HomeAuthProviderProps = {
+ children: ReactNode;
+};
+
+export type HomeAuthResponse = {
+ user?: MailboxSelectorUser;
+};
+
+export type HomeAccountMenuProps = {
+ user: MailboxSelectorUser;
+};
export type HomeAction = {
href: string;
diff --git a/src/components/components-nav.tsx b/src/components/components-nav.tsx
index 950ef79..135aa39 100644
--- a/src/components/components-nav.tsx
+++ b/src/components/components-nav.tsx
@@ -41,9 +41,9 @@ export function NavItem({ link }: { link: NavLink }) {
if (!Icon) return null;
const active = pathname === link.href || pathname.startsWith(`${link.href}/`);
const classes = cn(
- "flex h-9 items-center gap-3 rounded-r-full text-sm font-medium text-neutral-700 transition-colors hover:bg-blue-50",
+ "flex h-9 items-center gap-3 rounded-r-full text-sm font-medium text-neutral-700 transition-colors",
minimal && "relative mx-auto w-10 justify-center rounded-full px-0",
- active && "bg-blue-100 text-blue-900",
+ active ? "bg-blue-100 text-blue-900" : "hover:bg-stone-200/60",
dragOver && "bg-blue-50 text-blue-900 ring-1 ring-blue-200",
link.primary &&
"mb-3 h-12 w-fit rounded-2xl bg-blue-100 px-5 text-blue-950 shadow-sm hover:bg-blue-200",
@@ -80,7 +80,7 @@ export function NavItem({ link }: { link: NavLink }) {
size={21}
style={{ color: link.iconColor }}
/>
- {!minimal && <span className="flex-1">{link.label}</span>}
+ {!minimal && <span className={cn("flex-1", typeof link.count === "number" && link.count > 0 && "font-bold")}>{link.label}</span>}
{!minimal && typeof link.count === "number" && link.count > 0 && (
<span className="ml-auto mr-3 rounded-full px-2 py-0.5 text-sm font-semibold text-neutral-700">
{link.count > 99 ? "99+" : link.count}
@@ -142,7 +142,7 @@ export function NavItem({ link }: { link: NavLink }) {
style={{ color: link.iconColor }}
size={18}
/>
- {!minimal && <span className="flex-1">{link.label}</span>}
+ {!minimal && <span className={cn("flex-1", typeof link.count === "number" && link.count > 0 && "font-bold")}>{link.label}</span>}
{!minimal && typeof link.count === "number" && link.count > 0 && (
<span className="ml-auto mr-3 rounded-full px-2 py-0.5 text-sm font-semibold text-neutral-700">
{link.count > 99 ? "99+" : link.count}
diff --git a/src/components/compose/compose-form.tsx b/src/components/compose/compose-form.tsx
index 024f6b9..a58bab2 100644
--- a/src/components/compose/compose-form.tsx
+++ b/src/components/compose/compose-form.tsx
@@ -2,7 +2,7 @@
import { useEffect, useMemo, useRef, useState } from "react";
import type { DragEvent } from "react";
-import { FileText, Forward, Maximize2, Minimize2, Paperclip, Reply, Trash2, X } from "lucide-react";
+import { ChevronUp, FileText, Forward, Maximize2, Minimize2, Minus, Paperclip, Reply, Trash2, X } from "lucide-react";
import { useRouter } from "next/navigation";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
@@ -63,6 +63,7 @@ export function ComposeForm({
const [attachmentPolicy, setAttachmentPolicy] = useState<ComposeAttachmentPolicy>({ maxMb: 25, cloudThresholdBytes: 3_000_000 });
const [draggingFiles, setDraggingFiles] = useState(false);
const [modalMode, setModalMode] = useState(false);
+ const [minimized, setMinimized] = useState(false);
const [toast, setToast] = useState<Toast>(null);
const [loading, setLoading] = useState(false);
const [loadingDraft, setLoadingDraft] = useState(false);
@@ -488,15 +489,17 @@ export function ComposeForm({
const frameClass =
mode === "popup"
- ? modalMode
+ ? minimized
+ ? "fixed bottom-0 right-8 z-40 flex h-9 w-[min(260px,calc(100vw-32px))] flex-col overflow-hidden rounded-t-lg border border-neutral-200 bg-white shadow-2xl"
+ : modalMode
? "fixed left-1/2 top-1/2 z-50 flex h-[86vh] w-[min(860px,calc(100vw-32px))] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-lg bg-white shadow-2xl"
- : "fixed bottom-4 right-4 z-40 flex h-[min(520px,calc(100vh-88px))] w-[min(560px,calc(100vw-32px))] flex-col overflow-hidden rounded-lg border border-neutral-200 bg-white shadow-2xl"
+ : "fixed bottom-0 right-8 z-40 flex h-[min(520px,calc(100vh-88px))] w-[min(560px,calc(100vw-32px))] flex-col overflow-hidden rounded-t-lg border border-neutral-200 bg-white shadow-2xl"
: "relative flex h-full min-h-[720px] w-full max-w-4xl flex-col overflow-hidden rounded-xl border border-neutral-200 bg-white shadow-sm";
return (
<>
{agentReview && <SendReview approvalId={agentReview.approvalId} snapshot={agentReview.snapshot} onClose={() => setAgentReview(null)} onSent={() => { setAgentReview(null); if (onClose) onClose(); else router.push("/sent"); }} />}
- {mode === "popup" && modalMode && <div className="fixed inset-0 z-40 bg-neutral-950/65" aria-hidden="true" />}
+ {mode === "popup" && modalMode && !minimized && <div className="fixed inset-0 z-40 bg-neutral-950/65" aria-hidden="true" />}
{toast && (
<div
className={cn(
@@ -507,14 +510,14 @@ export function ComposeForm({
{toast.message}
</div>
)}
- <form onSubmit={onSubmit} className={frameClass} role={modalMode ? "dialog" : undefined} aria-modal={modalMode || undefined} aria-label={modalMode ? "Compose message" : undefined} onKeyDown={(event) => { if (modalMode && event.key === "Escape") { event.preventDefault(); setModalMode(false); } }} onDragEnterCapture={onFileDragEnter} onDragOverCapture={onFileDragOver} onDragLeaveCapture={onFileDragLeave} onDropCapture={onFileDrop}>
- {draggingFiles && (
+ <form onSubmit={onSubmit} className={frameClass} role={modalMode && !minimized ? "dialog" : undefined} aria-modal={modalMode && !minimized || undefined} aria-label={modalMode && !minimized ? "Compose message" : undefined} onKeyDown={(event) => { if (modalMode && !minimized && event.key === "Escape") { event.preventDefault(); setModalMode(false); } }} onDragEnterCapture={minimized ? undefined : onFileDragEnter} onDragOverCapture={minimized ? undefined : onFileDragOver} onDragLeaveCapture={minimized ? undefined : onFileDragLeave} onDropCapture={minimized ? undefined : onFileDrop}>
+ {draggingFiles && !minimized && (
<div className="pointer-events-none absolute inset-0 z-30 flex items-center justify-center border-2 border-dashed border-blue-400 bg-blue-50/90 text-sm font-medium text-blue-700" aria-hidden="true">
Drop files to attach
</div>
)}
- <div className="flex h-9 items-center justify-between bg-neutral-800 px-4 text-sm font-medium text-white">
- <span className="flex items-center gap-2">
+ <div className="flex h-9 shrink-0 items-center justify-between bg-neutral-800 px-4 text-sm font-medium text-white">
+ <span className="flex min-w-0 items-center gap-2 truncate">
{threading?.inReplyTo && <Reply className="h-3.5 w-3.5 text-neutral-300" />}
{!threading?.inReplyTo && /^fwd?:/i.test(subject) && <Forward className="h-3.5 w-3.5 text-neutral-300" />}
{loadingDraft
@@ -528,8 +531,11 @@ export function ComposeForm({
: "New Message"}
</span>
{mode === "popup" && (
- <div className="flex items-center gap-3 text-neutral-300">
- <button type="button" onClick={() => setModalMode((current) => !current)} aria-label={modalMode ? "Restore floating composer" : "Open composer as modal"} title={modalMode ? "Restore floating composer" : "Open composer as modal"} className="rounded p-1 hover:bg-neutral-700 hover:text-white">
+ <div className="flex shrink-0 items-center gap-3 text-neutral-300">
+ <button type="button" onClick={() => { setMinimized((current) => !current); setDraggingFiles(false); }} aria-label={minimized ? "Restore composer" : "Minimize composer"} title={minimized ? "Restore composer" : "Minimize composer"} className="rounded p-1 hover:bg-neutral-700 hover:text-white">
+ {minimized ? <ChevronUp className="h-4 w-4" /> : <Minus className="h-4 w-4" />}
+ </button>
+ <button type="button" onClick={() => { if (minimized) setMinimized(false); setModalMode((current) => !current); }} aria-label={modalMode ? "Restore floating composer" : "Open composer as modal"} title={modalMode ? "Restore floating composer" : "Open composer as modal"} className="rounded p-1 hover:bg-neutral-700 hover:text-white">
{modalMode ? <Minimize2 className="h-4 w-4" /> : <Maximize2 className="h-4 w-4" />}
</button>
<button type="button" onClick={onClose} aria-label="Close composer" className="rounded p-1 hover:bg-neutral-700 hover:text-white">
@@ -538,6 +544,7 @@ export function ComposeForm({
</div>
)}
</div>
+ <div className={cn("flex min-h-0 flex-1 flex-col", minimized && "hidden")}>
<div className="border-b border-neutral-100 px-4 py-1 flex flex-row items-center">
<Label htmlFor={`${mode}-from`} className="text-sm text-neutral-500">From</Label>
<Select
@@ -677,6 +684,7 @@ export function ComposeForm({
</>
}
/>
+ </div>
</form>
</>
);
diff --git a/src/components/mailbox-selector-types.d.ts b/src/components/mailbox-selector-types.d.ts
index 12bb04c..33ede71 100644
--- a/src/components/mailbox-selector-types.d.ts
+++ b/src/components/mailbox-selector-types.d.ts
@@ -8,6 +8,10 @@ export type MailboxSelectorUser = {
hasAvatar: boolean;
};
+export type MailboxSelectorProps = {
+ initialUser?: MailboxSelectorUser;
+};
+
export type AccountAvatarProps = {
name: string;
colorSeed?: string;
diff --git a/src/components/mailbox-selector.tsx b/src/components/mailbox-selector.tsx
index 3b8415b..0a572d4 100644
--- a/src/components/mailbox-selector.tsx
+++ b/src/components/mailbox-selector.tsx
@@ -25,6 +25,7 @@ import type {
AccountAvatarProps,
MailboxAccountRowProps,
MailboxSelectorUser,
+ MailboxSelectorProps,
} from "./mailbox-selector-types";
import {
getAccountInitial,
@@ -110,13 +111,13 @@ function MailboxAccountRow({ mailbox, unread, avatarUrl, onSelect }: MailboxAcco
);
}
-export function MailboxSelector() {
+export function MailboxSelector({ initialUser }: MailboxSelectorProps = {}) {
const { selectedMailbox, setSelectedMailbox, mailboxes, isLoading } = useSelectedMailbox();
const pathname = usePathname();
const router = useRouter();
const [open, setOpen] = useState(false);
- const [user, setUser] = useState<MailboxSelectorUser | null>(null);
- const [hasAvatar, setHasAvatar] = useState(false);
+ const [user, setUser] = useState<MailboxSelectorUser | null>(initialUser ?? null);
+ const [hasAvatar, setHasAvatar] = useState(!!initialUser?.hasAvatar);
const [avatarUrl, setAvatarUrl] = useState("/api/profile/avatar");
const [mailboxAvatarUrls, setMailboxAvatarUrls] = useState<Record<string, string>>({});
const ref = useRef<HTMLDivElement>(null);
@@ -187,7 +188,7 @@ export function MailboxSelector() {
return () => window.removeEventListener(MAILBOX_AVATAR_CHANGED_EVENT, onMailboxAvatarChanged);
}, []);
- if (isLoading) {
+ if (isLoading && !initialUser) {
return <Skeleton className="h-10 w-10 rounded-full" />;
}
diff --git a/src/components/message-actions/message-actions.tsx b/src/components/message-actions/message-actions.tsx
index 600a77e..e7c32b6 100644
--- a/src/components/message-actions/message-actions.tsx
+++ b/src/components/message-actions/message-actions.tsx
@@ -2,9 +2,10 @@
import { createElement, useState, useMemo, useCallback } from "react";
import { useRouter } from "next/navigation";
-import { Archive, Ban, BellOff, FileCode2, Forward, Mail, MailOpen, MoreVertical, Reply, ReplyAll, ShieldAlert, Trash2 } from "lucide-react";
+import { Archive, Ban, BellOff, Clock, FileCode2, Forward, Mail, MailOpen, MoreVertical, Reply, ReplyAll, ShieldAlert, Trash2 } from "lucide-react";
import { useCompose } from "@/components/compose/compose-context";
import { MessageSourceDialog } from "@/components/messages/message-source-dialog";
+import { MessageSnoozeDialog } from "./message-snooze-dialog";
import { useHotkeys, useShortcuts } from "@/components/shortcuts";
import { Button } from "@/components/ui/button";
import { Tooltip } from "@/components/ui/tooltip";
@@ -50,6 +51,7 @@ export function MessageActions({
const [error, setError] = useState<string | null>(null);
const [moreOpen, setMoreOpen] = useState(false);
const [sourceOpen, setSourceOpen] = useState(false);
+ const [snoozeOpen, setSnoozeOpen] = useState(false);
const runAction = useCallback(async (action: BulkMessageAction) => {
setMoreOpen(false);
@@ -223,159 +225,182 @@ export function MessageActions({
const moveActions = getMoveMessageActions(status, direction);
return (
- <div className="flex flex-wrap items-center justify-end gap-3 text-neutral-600">
+ <div className="flex flex-wrap items-center gap-3 text-neutral-600 flex-1 min-w-0">
{error && <span className="text-xs text-red-600">{error}</span>}
- <div className="flex flex-wrap items-center justify-end gap-1 sm:gap-2">
- <Tooltip label={shortcutsEnabled ? "Reply (r)" : "Reply"}>
+
+ <Tooltip label={shortcutsEnabled ? "Archive (e)" : "Archive"}>
+ <Button
+ variant="ghost"
+ size="roundedSM"
+ aria-label={shortcutsEnabled ? "Archive (e)" : "Archive"}
+ disabled={disabled || status === "archived"}
+ onClick={() => runAction("archive")}
+ >
+ <Archive size={iconSize} />
+ </Button>
+ </Tooltip>
+ <Tooltip label={shortcutsEnabled ? "Report spam (!)" : "Report spam"}>
+ <Button
+ variant="ghost"
+ size="roundedSM"
+ aria-label={shortcutsEnabled ? "Report spam (!)" : "Report spam"}
+ disabled={disabled || status === "spam" || direction !== "inbound"}
+ onClick={() => runAction("spam")}
+ >
+ <ShieldAlert size={iconSize} />
+ </Button>
+ </Tooltip>
+ <Tooltip label={shortcutsEnabled ? "Delete (#)" : "Delete"}>
+ <Button
+ variant="ghost"
+ size="roundedSM"
+ aria-label={shortcutsEnabled ? "Move to trash (#)" : "Move to trash"}
+ disabled={disabled || status === "trash"}
+ onClick={() => runAction("trash")}
+ >
+ <Trash2 size={iconSize} />
+ </Button>
+ </Tooltip>
+ <span className="h-5 mx-2 bg-gray-200 w-px inline-block" />
+
+
+ <Tooltip label={shortcutsEnabled ? "Reply (r)" : "Reply"}>
+ <Button
+ type="button"
+ variant="ghost"
+ size="roundedSM"
+ aria-label={shortcutsEnabled ? "Reply (r)" : "Reply"}
+ disabled={disabled}
+ onClick={() => handleReply("reply")}
+ >
+ <Reply size={iconSize} />
+ </Button>
+ </Tooltip>
+ {canReplyAll && (
+ <Tooltip label="Reply all">
<Button
type="button"
variant="ghost"
- size="sm"
- aria-label={shortcutsEnabled ? "Reply (r)" : "Reply"}
+ size="roundedSM"
+ aria-label="Reply all"
disabled={disabled}
- onClick={() => handleReply("reply")}
- >
- <Reply size={18} />
- </Button>
- </Tooltip>
- {canReplyAll && (
- <Tooltip label="Reply all">
- <Button
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Reply all"
- disabled={disabled}
- onClick={() => handleReply("replyAll")}
- >
- <ReplyAll size={18} />
- </Button>
- </Tooltip>
- )}
- {message && messageMeta && (
- <Tooltip label="Forward">
- <Button
- type="button"
- variant="ghost"
- size="sm"
- aria-label="Forward"
- disabled={disabled}
- onClick={() => void handleForward()}
- >
- <Forward size={18} />
- </Button>
- </Tooltip>
- )}
- <Tooltip label={shortcutsEnabled ? "Archive (e)" : "Archive"}>
- <Button
- variant="ghost"
- size="sm"
- aria-label={shortcutsEnabled ? "Archive (e)" : "Archive"}
- disabled={disabled || status === "archived"}
- onClick={() => runAction("archive")}
+ onClick={() => handleReply("replyAll")}
>
- <Archive size={18} />
+ <ReplyAll size={iconSize} />
</Button>
</Tooltip>
- <Tooltip label={shortcutsEnabled ? "Report spam (!)" : "Report spam"}>
- <Button
- variant="ghost"
- size="sm"
- aria-label={shortcutsEnabled ? "Report spam (!)" : "Report spam"}
- disabled={disabled || status === "spam" || direction !== "inbound"}
- onClick={() => runAction("spam")}
- >
- <ShieldAlert size={18} />
- </Button>
- </Tooltip>
- <Tooltip label={shortcutsEnabled ? "Delete (#)" : "Delete"}>
+ )}
+ {message && messageMeta && (
+ <Tooltip label="Forward">
<Button
+ type="button"
variant="ghost"
- size="sm"
- aria-label={shortcutsEnabled ? "Move to trash (#)" : "Move to trash"}
- disabled={disabled || status === "trash"}
- onClick={() => runAction("trash")}
+ size="roundedSM"
+ aria-label="Forward"
+ disabled={disabled}
+ onClick={() => void handleForward()}
>
- <Trash2 size={18} />
+ <Forward size={iconSize} />
</Button>
</Tooltip>
- <Tooltip label={read ? "Mark as unread" : "Mark as read"}>
+ )}
+
+ <Tooltip label={read ? "Mark as unread" : "Mark as read"}>
+ <Button
+ variant="ghost"
+ size="roundedSM"
+ aria-label={read ? "Mark as unread" : "Mark as read"}
+ disabled={disabled}
+ onClick={() => runAction(markAction)}
+ >
+ {read ? <Mail size={iconSize} /> : <MailOpen size={iconSize} />}
+ </Button>
+ </Tooltip>
+ <div className="relative">
+ <Tooltip label="More actions">
<Button
+ type="button"
variant="ghost"
- size="sm"
- aria-label={read ? "Mark as unread" : "Mark as read"}
+ size="roundedSM"
+ aria-label="More actions"
+ aria-expanded={moreOpen}
disabled={disabled}
- onClick={() => runAction(markAction)}
+ onClick={() => setMoreOpen((open) => !open)}
>
- {read ? <Mail size={18} /> : <MailOpen size={18} />}
+ <MoreVertical size={iconSize} />
</Button>
</Tooltip>
- <div className="relative">
- <Tooltip label="More actions">
- <Button
- type="button"
- variant="ghost"
- size="sm"
- aria-label="More actions"
- aria-expanded={moreOpen}
- disabled={disabled}
- onClick={() => setMoreOpen((open) => !open)}
- >
- <MoreVertical size={18} />
- </Button>
- </Tooltip>
- {moreOpen && (
- <div className="absolute right-0 z-20 mt-2 w-54 rounded-xl border border-neutral-200 bg-white p-2 shadow-lg">
- {direction === "inbound" && (
- <>
- <button
- type="button"
+
+
+ {moreOpen && (
+ <div className="absolute right-0 top-8 z-20 w-54 rounded-xl border border-neutral-200 bg-white p-2 shadow-lg">
+ {direction === "inbound" && status === "received" && (
+ <button
+ type="button"
+ className="flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-sm text-neutral-700 hover:bg-neutral-100"
+ onClick={() => { setMoreOpen(false); setSnoozeOpen(true); }}
+ >
+ <Clock className="h-4 w-4" />
+ Snooze
+ </button>
+ )}
+ {direction === "inbound" && (
+ <>
+ <button
+ type="button"
className="flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-sm text-neutral-700 hover:bg-neutral-100 disabled:cursor-not-allowed disabled:text-neutral-400"
disabled={!unsubscribeUrl && status === "trash"}
onClick={() => void onUnsubscribe()}
>
<BellOff className="h-4 w-4 shrink-0" />
Unsubscribe
- </button>
- <button
- type="button"
+ </button>
+ <button
+ type="button"
className="flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-sm text-neutral-700 hover:bg-neutral-100"
- onClick={() => void onBlockContact()}
- >
- <Ban className="h-4 w-4" />
- Block contact
- </button>
- <hr className="my-1 border-neutral-100" />
- </>
- )}
+ onClick={() => void onBlockContact()}
+ >
+ <Ban className="h-4 w-4" />
+ Block contact
+ </button>
+ <hr className="my-1 border-neutral-100" />
+ </>
+ )}
+ <button
+ type="button"
+ className="flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-sm text-neutral-700 hover:bg-neutral-100"
+ onClick={() => { setMoreOpen(false); setSourceOpen(true); }}
+ >
+ <FileCode2 className="h-4 w-4" />
+ Show original
+ </button>
+ <hr className="my-1 border-neutral-100" />
+ <p className="mt-1 px-3 pb-1 pt-2 text-sm font-medium text-neutral-500">
+ Move to
+ </p>
+ {moveActions.map((item) => (
<button
+ key={item.action}
type="button"
className="flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-sm text-neutral-700 hover:bg-neutral-100"
- onClick={() => { setMoreOpen(false); setSourceOpen(true); }}
+ onClick={() => void runAction(item.action)}
>
- <FileCode2 className="h-4 w-4" />
- Show original
+ {createElement(item.icon, { size: 16 })}
+ {item.label}
</button>
- <hr className="my-1 border-neutral-100" />
- <p className="mt-1 px-3 pb-1 pt-2 text-sm font-medium text-neutral-500">
- Move to
- </p>
- {moveActions.map((item) => (
- <button
- key={item.action}
- type="button"
- className="flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-sm text-neutral-700 hover:bg-neutral-100"
- onClick={() => void runAction(item.action)}
- >
- {createElement(item.icon, { size: 16 })}
- {item.label}
- </button>
- ))}
- </div>
- )}
- </div>
+ ))}
+ </div>
+ )}
+
</div>
+
<MessageSourceDialog messageId={messageId} open={sourceOpen} onOpenChange={setSourceOpen} />
+ <MessageSnoozeDialog messageId={messageId} open={snoozeOpen} onOpenChange={setSnoozeOpen} />
+
+ <span className="flex-1" />
</div>
);
}
+
+
+const iconSize = 16;
diff --git a/src/components/message-actions/message-snooze-dialog.tsx b/src/components/message-actions/message-snooze-dialog.tsx
new file mode 100644
index 0000000..58d7fbe
--- /dev/null
+++ b/src/components/message-actions/message-snooze-dialog.tsx
@@ -0,0 +1,56 @@
+"use client";
+
+import { useState } from "react";
+import { getSnoozePresets, snoozeMessage } from "@/components/messages/message-list-row-actions-utils";
+import { Button } from "@/components/ui/button";
+import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog";
+import { Input } from "@/components/ui/input";
+import type { MessageSnoozeDialogProps } from "./types";
+
+export function MessageSnoozeDialog({ messageId, open, onOpenChange }: MessageSnoozeDialogProps) {
+ const [snoozedUntil, setSnoozedUntil] = useState(() => getSnoozePresets()[0].value);
+ const [snoozing, setSnoozing] = useState(false);
+ const [error, setError] = useState<string | null>(null);
+ const snoozePresets = getSnoozePresets();
+
+ async function handleSnooze() {
+ setSnoozing(true);
+ setError(null);
+ try {
+ await snoozeMessage(messageId, snoozedUntil);
+ onOpenChange(false);
+ } catch (nextError) {
+ setError(nextError instanceof Error ? nextError.message : "Unable to snooze message");
+ } finally {
+ setSnoozing(false);
+ }
+ }
+
+ return (
+ <Dialog open={open} onOpenChange={onOpenChange}>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Snooze email</DialogTitle>
+ <DialogDescription>Hide this email from the inbox until the time you choose.</DialogDescription>
+ </DialogHeader>
+ <div className="space-y-4">
+ <div className="grid gap-2 sm:grid-cols-3">
+ {snoozePresets.map((preset) => (
+ <Button key={preset.label} type="button" variant="outline" size="sm" onClick={() => setSnoozedUntil(preset.value)}>
+ {preset.label}
+ </Button>
+ ))}
+ </div>
+ <div className="space-y-2">
+ <label htmlFor={`header-snooze-until-${messageId}`} className="text-sm font-medium text-neutral-700">Select date and time</label>
+ <Input id={`header-snooze-until-${messageId}`} type="datetime-local" value={snoozedUntil} onChange={(event) => setSnoozedUntil(event.target.value)} />
+ </div>
+ {error && <p className="text-sm text-red-600">{error}</p>}
+ <Button type="button" onClick={() => void handleSnooze()} disabled={snoozing}>
+ {snoozing ? "Snoozing..." : "Snooze"}
+ </Button>
+ </div>
+ </DialogContent>
+ </Dialog>
+ );
+}
diff --git a/src/components/message-actions/types.d.ts b/src/components/message-actions/types.d.ts
index 5092dc5..1508ca3 100644
--- a/src/components/message-actions/types.d.ts
+++ b/src/components/message-actions/types.d.ts
@@ -22,6 +22,12 @@ export type MessageActionsProps = {
bodyHtml?: string | null;
};
+export type MessageSnoozeDialogProps = {
+ messageId: string;
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+};
+
export type ForwardDraftInput = {
mailboxId: string | null;
ownAddress?: string | null;
diff --git a/src/components/messages/conversation-thread.tsx b/src/components/messages/conversation-thread.tsx
index 7895618..e6998f6 100644
--- a/src/components/messages/conversation-thread.tsx
+++ b/src/components/messages/conversation-thread.tsx
@@ -52,7 +52,7 @@ export function ConversationThread({
aria-label={position === "before" ? "Earlier messages in this conversation" : "Later messages in this conversation"}
className={cn(position === (latestMessagesFirst ? "before" : "after") ? "pb-6" : "")}
>
- <ol className={cn(!collapsed && "divide-y divide-neutral-200/50", latestMessagesFirst ? "border-y" : "border-b", "border-neutral-200")}>
+ <ol className={cn(!collapsed && "divide-y divide-neutral-200/50", latestMessagesFirst ? "border-t" : "border-b", "border-neutral-200")}>
<li className={"border-t-0"}>
<ConversationMessageCard
message={firstMessage}
diff --git a/src/components/messages/message-detail-navigation-types.d.ts b/src/components/messages/message-detail-navigation-types.d.ts
new file mode 100644
index 0000000..e71d155
--- /dev/null
+++ b/src/components/messages/message-detail-navigation-types.d.ts
@@ -0,0 +1,36 @@
+import type { ReactNode } from "react";
+import type { MessageNavigationEntry } from "@/app/api/messages/navigation/types";
+import type { MessageFolderConfig } from "./types";
+
+export type MessageDetailNavigationProviderProps = {
+ children: ReactNode;
+ config: MessageFolderConfig;
+};
+
+export type MessageDetailNavigationProps = {
+ messageId: string;
+ unread: boolean;
+};
+
+export type MessageDetailNavigationSnapshot = {
+ key: string;
+ entries: MessageNavigationEntry[];
+};
+
+export type OpenedUnreadMessages = {
+ key: string;
+ ids: Set<string>;
+};
+
+export type MessageDetailNavigationContextValue = {
+ entries: MessageNavigationEntry[];
+ hrefPrefix: string;
+ recordUnread: (messageId: string) => void;
+};
+
+export type MessageDetailNavigationState = {
+ previousId: string | null;
+ nextId: string | null;
+ unreadOrder: number;
+ totalUnread: number;
+};
diff --git a/src/components/messages/message-detail-navigation-utils.ts b/src/components/messages/message-detail-navigation-utils.ts
new file mode 100644
index 0000000..1f98bcb
--- /dev/null
+++ b/src/components/messages/message-detail-navigation-utils.ts
@@ -0,0 +1,34 @@
+import type { MessageNavigationEntry } from "@/app/api/messages/navigation/types";
+import type { MessageDetailNavigationState } from "./message-detail-navigation-types";
+
+const openedUnreadKey = "mailflare-navigation-opened-unread";
+
+export function rememberOpenedUnreadMessage(messageId: string) {
+ try {
+ sessionStorage.setItem(openedUnreadKey, messageId);
+ } catch {
+ // Navigation remains available when browser storage is disabled.
+ }
+}
+
+export function takeOpenedUnreadMessage(): string | null {
+ try {
+ const messageId = sessionStorage.getItem(openedUnreadKey);
+ sessionStorage.removeItem(openedUnreadKey);
+ return messageId;
+ } catch {
+ return null;
+ }
+}
+
+export function getMessageDetailNavigationState(entries: MessageNavigationEntry[], currentId: string): MessageDetailNavigationState {
+ const unread = entries.filter((entry) => entry.unread);
+ const ordered = [...unread, ...entries.filter((entry) => !entry.unread)];
+ const index = ordered.findIndex((entry) => entry.id === currentId);
+ return {
+ previousId: index > 0 ? ordered[index - 1].id : null,
+ nextId: index >= 0 ? ordered[index + 1]?.id ?? null : null,
+ unreadOrder: index >= 0 && index < unread.length ? index + 1 : 0,
+ totalUnread: unread.length,
+ };
+}
diff --git a/src/components/messages/message-detail-navigation.tsx b/src/components/messages/message-detail-navigation.tsx
new file mode 100644
index 0000000..adeb987
--- /dev/null
+++ b/src/components/messages/message-detail-navigation.tsx
@@ -0,0 +1,94 @@
+"use client";
+
+import { createContext, useCallback, useContext, useEffect, useState } from "react";
+import { useRouter } from "next/navigation";
+import { ChevronLeft, ChevronRight } from "lucide-react";
+import { Button } from "@/components/ui/button";
+import { Tooltip } from "@/components/ui/tooltip";
+import { useSelectedMailbox } from "@/components/mailbox-provider";
+import { authFetch } from "@/lib/auth/client";
+import type { MessageNavigationResponse } from "@/app/api/messages/navigation/types";
+import type { MessageDetailNavigationContextValue, MessageDetailNavigationProps, MessageDetailNavigationProviderProps, MessageDetailNavigationSnapshot, OpenedUnreadMessages } from "./message-detail-navigation-types";
+import { getMessageDetailNavigationState, takeOpenedUnreadMessage } from "./message-detail-navigation-utils";
+import { useConversationView } from "./use-conversation-view";
+
+const NavigationContext = createContext<MessageDetailNavigationContextValue | null>(null);
+
+export function MessageDetailNavigationProvider({ children, config }: MessageDetailNavigationProviderProps) {
+ const { selectedMailbox, isLoading: mailboxesLoading } = useSelectedMailbox();
+ const [conversationView] = useConversationView();
+ const grouped = conversationView && config.folder !== "drafts";
+ const mailboxId = selectedMailbox?.id;
+ const key = `${config.folder}:${config.folderId ?? ""}:${mailboxId ?? "all"}:${grouped}`;
+ const [snapshot, setSnapshot] = useState<MessageDetailNavigationSnapshot>({ key: "", entries: [] });
+ const [openedUnread, setOpenedUnread] = useState<OpenedUnreadMessages>({ key: "", ids: new Set() });
+ const recordUnread = useCallback((messageId: string) => {
+ setOpenedUnread((current) => {
+ const ids = new Set(current.key === key ? current.ids : []);
+ ids.add(messageId);
+ return { key, ids };
+ });
+ }, [key]);
+
+ useEffect(() => {
+ const messageId = takeOpenedUnreadMessage();
+ if (messageId) recordUnread(messageId);
+ }, [recordUnread]);
+
+ useEffect(() => {
+ if (mailboxesLoading) return;
+ let cancelled = false;
+ const params = new URLSearchParams({ folder: config.folder });
+ if (config.folderId) params.set("folderId", config.folderId);
+ if (mailboxId) params.set("mailboxId", mailboxId);
+ if (grouped) params.set("group", "thread");
+ void authFetch(`/api/messages/navigation?${params.toString()}`)
+ .then((response) => {
+ if (!response.ok) throw new Error("Unable to load message navigation");
+ return response.json() as Promise<MessageNavigationResponse>;
+ })
+ .then((response) => {
+ if (!cancelled) setSnapshot({ key, entries: response.messages });
+ })
+ .catch(() => {
+ if (!cancelled) setSnapshot({ key, entries: [] });
+ });
+ return () => { cancelled = true; };
+ }, [config.folder, config.folderId, grouped, key, mailboxId, mailboxesLoading]);
+
+ const unreadIds = openedUnread.key === key ? openedUnread.ids : null;
+ const entries = snapshot.key === key
+ ? snapshot.entries.map((entry) => ({ ...entry, unread: entry.unread || !!unreadIds?.has(entry.id) }))
+ : [];
+ return <NavigationContext.Provider value={{ entries, hrefPrefix: config.hrefPrefix, recordUnread }}>{children}</NavigationContext.Provider>;
+}
+
+export function MessageDetailNavigation({ messageId, unread }: MessageDetailNavigationProps) {
+ const context = useContext(NavigationContext);
+ const router = useRouter();
+ useEffect(() => {
+ if (unread) context?.recordUnread(messageId);
+ }, [context?.recordUnread, messageId, unread]);
+ if (!context) return null;
+ const { previousId, nextId, unreadOrder, totalUnread } = getMessageDetailNavigationState(context.entries, messageId);
+
+ return (
+ <div className="ml-auto flex shrink-0 items-center gap-2 text-neutral-500">
+ {totalUnread > 0 && (
+ <span className="mr-2 whitespace-nowrap text-xs" aria-live="polite">
+ {unreadOrder} of {totalUnread} unread
+ </span>
+ )}
+ <Tooltip label="Newer email">
+ <Button type="button" variant="ghost" size="roundedSM" aria-label="Newer email" disabled={!previousId} onClick={() => previousId && router.push(`${context.hrefPrefix}/${previousId}`)}>
+ <ChevronLeft size={18} />
+ </Button>
+ </Tooltip>
+ <Tooltip label="Older email">
+ <Button type="button" variant="ghost" size="roundedSM" aria-label="Older email" disabled={!nextId} onClick={() => nextId && router.push(`${context.hrefPrefix}/${nextId}`)}>
+ <ChevronRight size={18} />
+ </Button>
+ </Tooltip>
+ </div>
+ );
+}
diff --git a/src/components/messages/message-folder-page.tsx b/src/components/messages/message-folder-page.tsx
index c9e4dc5..7cfbeb3 100644
--- a/src/components/messages/message-folder-page.tsx
+++ b/src/components/messages/message-folder-page.tsx
@@ -20,6 +20,7 @@ import { BulkMessageToolbar } from "./bulk-message-toolbar";
import { MessageListRowActions } from "./message-list-row-actions";
import { dispatchMessageCountsDelta, toggleMessageStar } from "./message-list-row-actions-utils";
import { MessageNavigationProgress, useMessageNavigation } from "./message-navigation";
+import { rememberOpenedUnreadMessage } from "./message-detail-navigation-utils";
import { useConversationView } from "./use-conversation-view";
import type { MessageFolderPageProps, MessageListRowProps } from "./types";
import {
@@ -65,6 +66,7 @@ function MessageListRow({
function onMessageNavigate(event: MouseEvent<HTMLAnchorElement>) {
if (!read && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey) {
+ rememberOpenedUnreadMessage(message.id);
const previousThreadUnread = threadUnread;
setRead(true);
if (previousThreadUnread !== undefined) setThreadUnread(Math.max(0, previousThreadUnread - 1));
diff --git a/src/components/messages/message-list-visibility.tsx b/src/components/messages/message-list-visibility.tsx
index bff0fda..21079ef 100644
--- a/src/components/messages/message-list-visibility.tsx
+++ b/src/components/messages/message-list-visibility.tsx
@@ -3,7 +3,7 @@
import { createContext, useContext } from "react";
import type { MessageListVisibility } from "./types";
-export const MessageListVisibilityContext = createContext<MessageListVisibility>({ visible: true, toggle: () => undefined });
+export const MessageListVisibilityContext = createContext<MessageListVisibility>({ visible: true, toggle: () => undefined, singleColumn: false, backHref: "/inbox", backLabel: "Inbox" });
export function useMessageListVisibility() {
return useContext(MessageListVisibilityContext);
diff --git a/src/components/messages/message-reading-header-button-types.d.ts b/src/components/messages/message-reading-header-button-types.d.ts
new file mode 100644
index 0000000..6e6549c
--- /dev/null
+++ b/src/components/messages/message-reading-header-button-types.d.ts
@@ -0,0 +1,3 @@
+export type MessageReadingHeaderButtonProps = {
+ assistantVisible: boolean;
+};
diff --git a/src/components/messages/message-reading-header-button.tsx b/src/components/messages/message-reading-header-button.tsx
new file mode 100644
index 0000000..bfe478e
--- /dev/null
+++ b/src/components/messages/message-reading-header-button.tsx
@@ -0,0 +1,36 @@
+"use client";
+
+import { useRouter } from "next/navigation";
+import { ArrowLeft, Columns2 } from "lucide-react";
+import clsx from "clsx";
+import { Tooltip } from "@/components/ui/tooltip";
+import { useMessageListVisibility } from "./message-list-visibility";
+import type { MessageReadingHeaderButtonProps } from "./message-reading-header-button-types";
+
+export function MessageReadingHeaderButton({ assistantVisible }: MessageReadingHeaderButtonProps) {
+ const router = useRouter();
+ const { visible, toggle, singleColumn, backHref, backLabel } = useMessageListVisibility();
+ const label = singleColumn
+ ? `Back to ${backLabel}`
+ : assistantVisible ? null : visible ? "Hide email list" : "Show email list";
+
+ function handleClick() {
+ if (singleColumn) router.push(backHref);
+ else toggle();
+ }
+
+ return (
+ <Tooltip label={label} className={singleColumn ? "inline-flex" : "hidden lg:inline-flex"}>
+ <button
+ type="button"
+ className={clsx(!singleColumn && assistantVisible ? "opacity-40" : !singleColumn && !visible ? "opacity-60 hover:opacity-100" : "", (singleColumn || !assistantVisible) && "hover:bg-neutral-100 hover:text-neutral-900", "relative z-10 shrink-0 rounded-full p-2 text-neutral-600 duration-200")}
+ onClick={handleClick}
+ disabled={!singleColumn && assistantVisible}
+ aria-label={label ?? "Email list unavailable"}
+ aria-pressed={singleColumn ? undefined : visible}
+ >
+ {singleColumn ? <ArrowLeft size={18} /> : <Columns2 size={18} />}
+ </button>
+ </Tooltip>
+ );
+}
diff --git a/src/components/messages/message-split-layout.tsx b/src/components/messages/message-split-layout.tsx
index 2b433a0..737e369 100644
--- a/src/components/messages/message-split-layout.tsx
+++ b/src/components/messages/message-split-layout.tsx
@@ -8,8 +8,10 @@ import { readColumnWidth, readInitialColumnWidth, saveColumnWidth } from "@/comp
import { ResizeHandle } from "@/components/ui/resize-handle";
import { BulkMessageSelectionPane } from "./bulk-message-selection-pane";
import { MessageFolderPage } from "./message-folder-page";
+import { MessageDetailNavigationProvider } from "./message-detail-navigation";
import { MessageListVisibilityContext } from "./message-list-visibility";
import { readInitialMessageListVisible, saveMessageListVisible } from "./message-list-visibility-utils";
+import { useTwoColumnReading } from "./use-two-column-reading";
import type { MessageSplitLayoutProps, SelectedMessage } from "./types";
export function MessageSplitLayout({
@@ -22,12 +24,13 @@ export function MessageSplitLayout({
const [widthReady, setWidthReady] = useState(false);
const [containerWidth, setContainerWidth] = useState(0);
const [manualListVisible, setManualListVisible] = useState(true);
+ const [twoColumnReading] = useTwoColumnReading();
const containerRef = useRef<HTMLDivElement>(null);
const startWidth = useRef(listWidth);
const resizedWidth = useRef(listWidth);
const { userId, setForcedMinimal } = useSidebar();
const assistantOpen = useAssistantOpen();
- const listVisible = !assistantOpen && manualListVisible;
+ const listVisible = twoColumnReading && !assistantOpen && manualListVisible;
const detailPrefix = `${config.hrefPrefix}/`;
const selectedMessageId = pathname.startsWith(detailPrefix)
? pathname.slice(detailPrefix.length).split("/")[0]
@@ -66,7 +69,8 @@ export function MessageSplitLayout({
if (!selectedMessageId) return children;
return (
- <div ref={containerRef} className="h-full min-h-0 overflow-hidden lg:grid lg:transition-[grid-template-columns] lg:ease-in-out motion-reduce:transition-none" style={{ gridTemplateColumns: `${listVisible ? renderedListWidth : 0}px minmax(0,1fr)`, transitionDuration: widthReady ? "300ms" : "0ms" }}>
+ <div ref={containerRef} className="h-full min-h-0 overflow-hidden lg:grid lg:transition-[grid-template-columns] lg:ease-in-out motion-reduce:transition-none" style={{ gridTemplateColumns: twoColumnReading ? `${listVisible ? renderedListWidth : 0}px minmax(0,1fr)` : "minmax(0,1fr)", transitionDuration: widthReady ? "300ms" : "0ms" }}>
+ {twoColumnReading && (
<aside className={`relative hidden min-h-0 min-w-0 overflow-hidden bg-white lg:block ${listVisible ? "border-r border-neutral-200" : "pointer-events-none"}`} aria-hidden={!listVisible} inert={!listVisible}>
<div className={`h-full overflow-hidden transition-transform duration-300 ease-in-out motion-reduce:transition-none ${listVisible ? "translate-x-0" : "-translate-x-full"}`} style={{ width: renderedListWidth }}>
<MessageFolderPage
@@ -88,9 +92,11 @@ export function MessageSplitLayout({
onResizeEnd={() => saveColumnWidth(userId, "message-list", resizedWidth.current)}
/>
</aside>
- <MessageListVisibilityContext.Provider value={{ visible: listVisible, toggle: () => { const visible = !manualListVisible; setManualListVisible(visible); saveMessageListVisible(visible); } }}>
- <section className="min-h-0 min-w-0 overflow-hidden bg-white">
- {selectedMessages.length > 0 ? (
+ )}
+ <MessageListVisibilityContext.Provider value={{ visible: listVisible, toggle: () => { const visible = !manualListVisible; setManualListVisible(visible); saveMessageListVisible(visible); }, singleColumn: !twoColumnReading, backHref: config.hrefPrefix, backLabel: config.title }}>
+ <MessageDetailNavigationProvider config={config}>
+ <section className="min-h-0 min-w-0 overflow-hidden bg-white flex flex-col">
+ {twoColumnReading && selectedMessages.length > 0 ? (
<BulkMessageSelectionPane
selectedMessages={selectedMessages}
onClearSelection={() => setSelectedMessages([])}
@@ -99,6 +105,7 @@ export function MessageSplitLayout({
children
)}
</section>
+ </MessageDetailNavigationProvider>
</MessageListVisibilityContext.Provider>
</div>
);
diff --git a/src/components/messages/types.d.ts b/src/components/messages/types.d.ts
index d61b4a9..ee6e141 100644
--- a/src/components/messages/types.d.ts
+++ b/src/components/messages/types.d.ts
@@ -49,6 +49,9 @@ export type MessageSplitLayoutProps = {
export type MessageListVisibility = {
visible: boolean;
toggle: () => void;
+ singleColumn: boolean;
+ backHref: string;
+ backLabel: string;
};
export type BulkMessageToolbarProps = {
diff --git a/src/components/messages/use-two-column-reading.ts b/src/components/messages/use-two-column-reading.ts
new file mode 100644
index 0000000..f95228d
--- /dev/null
+++ b/src/components/messages/use-two-column-reading.ts
@@ -0,0 +1,39 @@
+import { useCallback, useLayoutEffect, useState } from "react";
+
+const STORAGE_KEY = "mailflare-two-column-reading";
+const CHANGE_EVENT = "mailflare:two-column-reading-changed";
+
+function readStored() {
+ try {
+ return localStorage.getItem(STORAGE_KEY) !== "off";
+ } catch {
+ return true;
+ }
+}
+
+export function useTwoColumnReading(): [boolean, (enabled: boolean) => void] {
+ const [enabled, setEnabled] = useState(true);
+
+ useLayoutEffect(() => {
+ const sync = () => setEnabled(readStored());
+ sync();
+ window.addEventListener(CHANGE_EVENT, sync);
+ window.addEventListener("storage", sync);
+ return () => {
+ window.removeEventListener(CHANGE_EVENT, sync);
+ window.removeEventListener("storage", sync);
+ };
+ }, []);
+
+ const update = useCallback((next: boolean) => {
+ try {
+ localStorage.setItem(STORAGE_KEY, next ? "on" : "off");
+ } catch {
+ // The preference still applies until this page is closed.
+ }
+ setEnabled(next);
+ window.dispatchEvent(new Event(CHANGE_EVENT));
+ }, []);
+
+ return [enabled, update];
+}
diff --git a/src/components/settings/inbox-reading-layout-settings.tsx b/src/components/settings/inbox-reading-layout-settings.tsx
new file mode 100644
index 0000000..78abe3b
--- /dev/null
+++ b/src/components/settings/inbox-reading-layout-settings.tsx
@@ -0,0 +1,20 @@
+"use client";
+
+import { Switch } from "@/components/ui/switch";
+import { useTwoColumnReading } from "@/components/messages/use-two-column-reading";
+
+export function InboxReadingLayoutSettings() {
+ const [twoColumnReading, setTwoColumnReading] = useTwoColumnReading();
+
+ return (
+ <label className="flex items-start gap-3 rounded-xl bg-neutral-50 p-4">
+ <span className="flex-1">
+ <span className="block text-sm font-medium text-neutral-900">Two column reading view</span>
+ <span className="mt-1 block text-sm text-neutral-500">
+ Show the email list beside an open email. Turn this off to read emails in one column.
+ </span>
+ </span>
+ <Switch checked={twoColumnReading} onCheckedChange={setTwoColumnReading} aria-label="Two column reading view" />
+ </label>
+ );
+}
diff --git a/src/components/ui/button.tsx b/src/components/ui/button.tsx
index 25212ab..166bb79 100644
--- a/src/components/ui/button.tsx
+++ b/src/components/ui/button.tsx
@@ -17,6 +17,7 @@ const buttonVariants = cva(
default: "h-10 px-6 py-2 rounded-xl",
sm: "h-8 rounded-lg px-3 text-xs",
lg: "h-11 rounded-xl px-8",
+ roundedSM: "rounded-full p-2 text-xs"
},
},
defaultVariants: {