Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(email-view): inline email detail and breadcrumbs (#6496)

dev-rb4573e958a28e
diff --git a/apps/web/src/features/block-email/EmailBlockAdapter.tsx b/apps/web/src/features/block-email/EmailBlockAdapter.tsx
index 4c65722723..f6115d1284 100644
--- a/apps/web/src/features/block-email/EmailBlockAdapter.tsx
+++ b/apps/web/src/features/block-email/EmailBlockAdapter.tsx
@@ -1,9 +1,5 @@
-import { AskMacroButton } from '@app/features/chat/ChatWithAgentButton';
-import { useEmailThreadState } from '@app/features/email-thread/context/email-thread-state-context';
+import type { EmailThreadHost } from '@app/features/email-thread/context/email-thread-context';
import { URL_PARAMS } from '@app/features/email-thread/core/location';
-import { EmailThread } from '@app/features/email-thread/email-thread';
-import { SidePanel } from '@components/app/side-panel';
-import { useSplitLayout } from '@components/app/split-layout/layout';
import {
useCanAutofocusSplitContent,
useSplitPanel,
@@ -17,19 +13,10 @@ import {
blockHotkeyScopeSignal,
} from '@core/signal/blockElement';
import { blockHandleSignal } from '@core/signal/load';
-import { buildMentionMarkdownString } from '@macro-inc/lexical-core';
import { useSearchParams } from '@solidjs/router';
-import {
- type Accessor,
- createEffect,
- createSignal,
- onCleanup,
- Show,
-} from 'solid-js';
-import { EmailTaskButton } from './component/EmailTaskButton';
-import { ModalsProvider } from './component/ModalsProvider';
-import { EmailSidePanelSections } from './component/sidepanel/EmailSidePanelSections';
+import { type Accessor, createEffect, createSignal, onCleanup } from 'solid-js';
import { TopBar } from './component/TopBar';
+import { EmailThreadHostView } from './EmailThreadHostView';
import { useEmailListNavigation } from './use-email-list-navigation';
import { registerEmailHotkeys } from './util/emailHotkeys';
@@ -45,7 +32,6 @@ export function EmailBlockAdapter(props: {
const split = useSplitPanel();
const listNavigation = useEmailListNavigation(props.threadId);
const canAutofocus = useCanAutofocusSplitContent();
- const { popoverSplit } = useSplitLayout();
const blockElement = blockElementSignal.get;
const hotkeyScope = blockHotkeyScopeSignal.get;
const focusContainer = () => blockElement()?.focus({ preventScroll: true });
@@ -66,94 +52,42 @@ export function EmailBlockAdapter(props: {
focusContainer();
focused = true;
});
- const createTask = () =>
- popoverSplit({
- type: 'component',
- id: 'task-compose',
- params: {
- initialTitle:
- props.title.length > 70
- ? `${props.title.slice(0, 70)}...`
- : props.title,
- initialContent: buildMentionMarkdownString({
- type: 'document',
- documentId: props.threadId(),
- documentName: props.title,
- blockName: 'email',
- }),
- },
- });
+ const host: EmailThreadHost = {
+ listNavigation,
+ targetMessageId,
+ focusContainer,
+ isActive: () => split?.isPanelActive() !== false,
+ registerKeyboard: (handlers) => {
+ registerEmailHotkeys(hotkeyScope(), handlers);
+ registerScopeSignalHotkey(hotkeyScope, {
+ hotkey: 'enter',
+ description: 'Reply to message',
+ keyDownHandler: handlers.activate,
+ hotkeyToken: TOKENS.block.focus,
+ hide: true,
+ });
+ registerScopeSignalHotkey(hotkeyScope, {
+ hotkey: 'escape',
+ description: 'Collapse or unselect message',
+ keyDownHandler: handlers.cancel,
+ hotkeyToken: TOKENS.email.cancelReply,
+ hide: true,
+ });
+ },
+ };
+
return (
- <EmailThread
+ <EmailThreadHostView
title={props.title}
threadId={props.threadId}
- host={{
- listNavigation,
- targetMessageId,
- focusContainer,
- isActive: () => split?.isPanelActive() !== false,
- registerKeyboard: (handlers) => {
- registerEmailHotkeys(hotkeyScope(), handlers);
- registerScopeSignalHotkey(hotkeyScope, {
- hotkey: 'enter',
- description: 'Reply to message',
- keyDownHandler: handlers.activate,
- hotkeyToken: TOKENS.block.focus,
- hide: true,
- });
- registerScopeSignalHotkey(hotkeyScope, {
- hotkey: 'escape',
- description: 'Collapse or unselect message',
- keyDownHandler: handlers.cancel,
- hotkeyToken: TOKENS.email.cancelReply,
- hide: true,
- });
- },
- }}
- header={
+ host={host}
+ topBar={({ createTask }) => (
<TopBar
id={props.threadId()}
title={props.title}
onCreateTask={createTask}
/>
- }
- actions={<ThreadActions title={props.title} onCreateTask={createTask} />}
- frame={(content) => (
- <ModalsProvider subject={props.title}>
- <SidePanel.Layout defaultOpen={false}>
- {content()}
- <EmailSidePanelSections
- threadId={props.threadId()}
- title={props.title}
- />
- </SidePanel.Layout>
- </ModalsProvider>
)}
/>
);
}
-
-function ThreadActions(props: { title: string; onCreateTask: () => void }) {
- const context = useEmailThreadState();
- return (
- <SidePanel.Section
- id="email-ai-actions"
- title="Actions"
- defaultOpen
- order={0}
- >
- <div class="m-px flex items-center justify-start gap-2">
- <Show when={context.thread()?.db_id}>
- {(id) => (
- <AskMacroButton
- entity={{ type: 'email', id: id(), name: props.title }}
- />
- )}
- </Show>
- <Show when={context.thread()?.db_id}>
- <EmailTaskButton onClick={props.onCreateTask} />
- </Show>
- </div>
- </SidePanel.Section>
- );
-}
diff --git a/apps/web/src/features/block-email/EmailThreadHostView.tsx b/apps/web/src/features/block-email/EmailThreadHostView.tsx
new file mode 100644
index 0000000000..4e81a57054
--- /dev/null
+++ b/apps/web/src/features/block-email/EmailThreadHostView.tsx
@@ -0,0 +1,106 @@
+import { AskMacroButton } from '@app/features/chat/ChatWithAgentButton';
+import type { EmailThreadHost } from '@app/features/email-thread/context/email-thread-context';
+import { useEmailThreadState } from '@app/features/email-thread/context/email-thread-state-context';
+import { EmailThread } from '@app/features/email-thread/email-thread';
+import { SidePanel } from '@components/app/side-panel';
+import { useSplitLayout } from '@components/app/split-layout/layout';
+import { buildMentionMarkdownString } from '@macro-inc/lexical-core';
+import type { Accessor, JSX } from 'solid-js';
+import { Show } from 'solid-js';
+import { EmailTaskButton } from './component/EmailTaskButton';
+import { ModalsProvider } from './component/ModalsProvider';
+import { EmailSidePanelSections } from './component/sidepanel/EmailSidePanelSections';
+
+export type EmailThreadHostViewContext = {
+ createTask: () => void;
+};
+
+export type EmailThreadHostViewProps = {
+ title: string;
+ threadId: Accessor<string>;
+ host: EmailThreadHost;
+ topBar?: (context: EmailThreadHostViewContext) => JSX.Element;
+ sidePanelHeaderToggle?: boolean;
+ shareOpen?: boolean;
+ onShareOpenChange?: (open: boolean) => void;
+};
+
+/**
+ * App-facing email thread body shared by block and in-view hosts.
+ * Host-specific focus, keyboard, list navigation, and top-bar composition
+ * arrive explicitly.
+ */
+export function EmailThreadHostView(props: EmailThreadHostViewProps) {
+ const { popoverSplit } = useSplitLayout();
+ const createTask = () =>
+ popoverSplit({
+ type: 'component',
+ id: 'task-compose',
+ params: {
+ initialTitle:
+ props.title.length > 70
+ ? `${props.title.slice(0, 70)}...`
+ : props.title,
+ initialContent: buildMentionMarkdownString({
+ type: 'document',
+ documentId: props.threadId(),
+ documentName: props.title,
+ blockName: 'email',
+ }),
+ },
+ });
+
+ return (
+ <EmailThread
+ title={props.title}
+ threadId={props.threadId}
+ host={props.host}
+ header={props.topBar?.({ createTask })}
+ actions={<ThreadActions title={props.title} onCreateTask={createTask} />}
+ frame={(content) => (
+ <ModalsProvider
+ threadId={props.threadId()}
+ subject={props.title}
+ shareOpen={props.shareOpen}
+ onShareOpenChange={props.onShareOpenChange}
+ >
+ <SidePanel.Layout
+ defaultOpen={false}
+ headerToggle={props.sidePanelHeaderToggle}
+ >
+ {content()}
+ <EmailSidePanelSections
+ threadId={props.threadId()}
+ title={props.title}
+ />
+ </SidePanel.Layout>
+ </ModalsProvider>
+ )}
+ />
+ );
+}
+
+function ThreadActions(props: { title: string; onCreateTask: () => void }) {
+ const context = useEmailThreadState();
+ return (
+ <SidePanel.Section
+ id="email-ai-actions"
+ title="Actions"
+ defaultOpen
+ order={0}
+ >
+ <div class="m-px flex items-center justify-start gap-2">
+ <Show when={context.thread()?.db_id}>
+ {(id) => (
+ <AskMacroButton
+ entity={{ type: 'email', id: id(), name: props.title }}
+ />
+ )}
+ </Show>
+ <Show when={context.thread()?.db_id}>
+ <EmailTaskButton onClick={props.onCreateTask} />
+ </Show>
+ </div>
+ </SidePanel.Section>
+ );
+}
diff --git a/apps/web/src/features/block-email/component/Block.tsx b/apps/web/src/features/block-email/component/Block.tsx
index 70666747b9..7468e6b23d 100644
--- a/apps/web/src/features/block-email/component/Block.tsx
+++ b/apps/web/src/features/block-email/component/Block.tsx
@@ -4,16 +4,13 @@ import { useGlobalNotificationSource } from '@components/app/GlobalAppState';
import { useSplitPanel } from '@components/app/split-layout/layoutUtils';
import { useBlockId } from '@core/block';
import { DocumentBlockContainer } from '@core/component/DocumentBlockContainer';
-import {
- EntityLoadGate,
- toEntityLoadError,
-} from '@core/component/EntityLoadGate';
+import { toEntityLoadError } from '@core/component/EntityLoadGate';
import { buildEntityData } from '@entity';
-import { EmailDebouncedReadMarker } from '@notifications';
import { useThreadQuery } from '@queries/email/thread';
import { representativeThreadMessage } from '@queries/email/thread-subject';
import { createMemo, Show, Suspense } from 'solid-js';
import { EmailBlockAdapter } from '../EmailBlockAdapter';
+import { EmailThreadLoadGate } from './EmailThreadLoadGate';
export default function BlockEmail() {
const blockId = useBlockId();
@@ -78,27 +75,22 @@ export default function BlockEmail() {
<Suspense>
<DocumentBlockContainer title={title() ?? 'Email'}>
<div class="size-full" tabIndex={-1}>
- <EntityLoadGate
+ <EmailThreadLoadGate
result={threadLoadResult}
- loadErrorTitle="Unable to load this email"
+ notificationSource={notificationSource}
+ threadId={threadId()}
+ linkId={threadData()?.thread?.link_id}
+ debounceTime={isPreview ? 1_500 : 100}
onRetry={() => void threadQuery.refetch()}
>
<Show when={threadId()}>
{(id) => (
- <>
- <EmailDebouncedReadMarker
- notificationSource={notificationSource}
- threadId={id()}
- linkId={threadData()?.thread?.link_id}
- debounceTime={isPreview ? 1_500 : 100}
- />
- <Suspense>
- <EmailBlockAdapter title={title()} threadId={id} />
- </Suspense>
- </>
+ <Suspense>
+ <EmailBlockAdapter title={title()} threadId={id} />
+ </Suspense>
)}
</Show>
- </EntityLoadGate>
+ </EmailThreadLoadGate>
</div>
</DocumentBlockContainer>
</Suspense>
diff --git a/apps/web/src/features/block-email/component/EmailThreadLoadGate.tsx b/apps/web/src/features/block-email/component/EmailThreadLoadGate.tsx
new file mode 100644
index 0000000000..b40350b8f9
--- /dev/null
+++ b/apps/web/src/features/block-email/component/EmailThreadLoadGate.tsx
@@ -0,0 +1,41 @@
+import {
+ EntityLoadGate,
+ type EntityLoadResult,
+} from '@core/component/EntityLoadGate';
+import { EmailDebouncedReadMarker } from '@notifications';
+import type { ComponentProps, ParentProps } from 'solid-js';
+import { Suspense } from 'solid-js';
+
+export type EmailThreadLoadGateProps<Data> = ParentProps<{
+ result: EntityLoadResult<Data>;
+ notificationSource: ComponentProps<
+ typeof EmailDebouncedReadMarker
+ >['notificationSource'];
+ threadId: string;
+ linkId?: string;
+ debounceTime?: number;
+ onRetry: () => void;
+}>;
+
+/** Shared load and read-state policy for every mounted email detail host. */
+export function EmailThreadLoadGate<Data>(
+ props: EmailThreadLoadGateProps<Data>
+) {
+ return (
+ <Suspense>
+ <EntityLoadGate
+ result={props.result}
+ loadErrorTitle="Unable to load this email"
+ onRetry={props.onRetry}
+ >
+ <EmailDebouncedReadMarker
+ notificationSource={props.notificationSource}
+ threadId={props.threadId}
+ linkId={props.linkId}
+ debounceTime={props.debounceTime}
+ />
+ {props.children}
+ </EntityLoadGate>
+ </Suspense>
+ );
+}
diff --git a/apps/web/src/features/block-email/component/ModalsProvider.tsx b/apps/web/src/features/block-email/component/ModalsProvider.tsx
index a24b3e7b09..035977c0fc 100644
--- a/apps/web/src/features/block-email/component/ModalsProvider.tsx
+++ b/apps/web/src/features/block-email/component/ModalsProvider.tsx
@@ -1,15 +1,36 @@
import { useEmailThreadState } from '@app/features/email-thread/context/email-thread-state-context';
import { getPermissions } from '@core/component/SharePermissions';
import {
- ShareBlockModal,
ShareDialogContext,
+ ShareModal,
} from '@core/component/TopBar/ShareButton';
import { ENABLE_EMAIL_SHARING } from '@core/constant/featureFlags';
-import { createSignal, type ParentProps, Show } from 'solid-js';
+import {
+ createSignal,
+ type ParentProps,
+ type Setter,
+ Show,
+ Suspense,
+} from 'solid-js';
-export function ModalsProvider(props: ParentProps<{ subject?: string }>) {
+export function ModalsProvider(
+ props: ParentProps<{
+ threadId: string;
+ subject?: string;
+ shareOpen?: boolean;
+ onShareOpenChange?: (open: boolean) => void;
+ }>
+) {
const email = useEmailThreadState();
- const [shareOpen, setShareOpen] = createSignal(false);
+ const [localShareOpen, setLocalShareOpen] = createSignal(false);
+ const shareOpen = () => props.shareOpen ?? localShareOpen();
+ const setShareOpen: Setter<boolean> = (next) => {
+ const open = typeof next === 'function' ? next(shareOpen()) : next;
+ props.onShareOpenChange?.(open);
+ if (props.shareOpen === undefined) setLocalShareOpen(() => open);
+ return open;
+ };
+
return (
<ShareDialogContext.Provider
value={{
@@ -20,10 +41,17 @@ export function ModalsProvider(props: ParentProps<{ subject?: string }>) {
>
{props.children}
<Show when={ENABLE_EMAIL_SHARING}>
- <ShareBlockModal
- name={props.subject}
- userPermissions={getPermissions(email.thread()?.access_level)}
- />
+ <Suspense>
+ <ShareModal
+ isSharePermOpen={shareOpen()}
+ setIsSharePermOpen={setShareOpen}
+ id={props.threadId}
+ blockAlias="email"
+ itemType="email"
+ name={props.subject ?? ''}
+ userPermissions={getPermissions(email.thread()?.access_level)}
+ />
+ </Suspense>
</Show>
</ShareDialogContext.Provider>
);
diff --git a/apps/web/src/features/block-email/component/TopBar.tsx b/apps/web/src/features/block-email/component/TopBar.tsx
index 09eb3273c6..7f85157c98 100644
--- a/apps/web/src/features/block-email/component/TopBar.tsx
+++ b/apps/web/src/features/block-email/component/TopBar.tsx
@@ -169,7 +169,7 @@ export function TopBar(props: {
icon: IconShared,
action: () => shareCtx.open(),
condition: () => ENABLE_EMAIL_SHARING,
- buttonComponent: () => <ShareTrigger />,
+ buttonComponent: () => <ShareTrigger id={props.id} blockType="email" />,
focusTarget: getShareDrawerRecipientInput,
};
diff --git a/apps/web/src/features/email-thread/primitives/thread-navigation.test.ts b/apps/web/src/features/email-thread/primitives/thread-navigation.test.ts
index c6d1fab11c..20b90dddf6 100644
--- a/apps/web/src/features/email-thread/primitives/thread-navigation.test.ts
+++ b/apps/web/src/features/email-thread/primitives/thread-navigation.test.ts
@@ -1,5 +1,9 @@
import { createRoot, createSignal } from 'solid-js';
import { afterEach, expect, it, vi } from 'vitest';
+import type {
+ EmailThreadHost,
+ EmailThreadListNavigation,
+} from '../context/email-thread-context';
import type { EmailThreadKeyboardHandlers } from '../core/thread-keyboard';
import { createThreadContext, message, thread } from '../tests/fixtures';
import { createEmailThreadState } from './email-thread-state';
@@ -52,7 +56,10 @@ it('leaves Enter to a focused button and still activates the thread container',
}
});
-function navigationWithList(ids: string[]) {
+function navigationWithList(
+ ids: string[],
+ listNavigation?: EmailThreadListNavigation
+) {
vi.useFakeTimers();
vi.stubGlobal('CSS', { escape: (value: string) => value });
const container = document.createElement('div');
@@ -70,11 +77,12 @@ function navigationWithList(ids: string[]) {
thread(ids.map((id) => message(id)))
);
const threadContext = createThreadContext({ thread: snapshot });
- const host = {
+ const host: EmailThreadHost = {
focusContainer: () => container.focus({ preventScroll: true }),
registerKeyboard: (registered: EmailThreadKeyboardHandlers) => {
handlers = registered;
},
+ listNavigation,
};
const context = createEmailThreadState(threadContext, host);
const navigation = createThreadNavigation(
@@ -97,6 +105,24 @@ function navigationWithList(ids: string[]) {
};
}
+it('delegates keyboard mark done to host list navigation', () => {
+ const markDone = vi.fn();
+ const state = navigationWithList(['last'], {
+ canPrevious: () => false,
+ canNext: () => false,
+ previous: vi.fn(),
+ next: vi.fn(),
+ markDone,
+ });
+
+ try {
+ expect(state.handlers()?.markDone()).toBe(true);
+ expect(markDone).toHaveBeenCalledWith(state.context.archiveThread);
+ } finally {
+ state.dispose();
+ }
+});
+
it.each(['next', 'previous'] as const)(
'%s-message navigation takes focus from the old details button before Enter expands the selected message',
(direction) => {
diff --git a/apps/web/src/features/email-thread/primitives/thread-navigation.ts b/apps/web/src/features/email-thread/primitives/thread-navigation.ts
index 2928ccfdd7..9e214a51d1 100644
--- a/apps/web/src/features/email-thread/primitives/thread-navigation.ts
+++ b/apps/web/src/features/email-thread/primitives/thread-navigation.ts
@@ -603,13 +603,18 @@ export function createThreadNavigation(
}
return true;
};
+ const markDone = () => {
+ if (!host.listNavigation) return context.archiveThread();
+ host.listNavigation.markDone(context.archiveThread);
+ return true;
+ };
onMount(() =>
host.registerKeyboard?.({
replyToFocusedMessage: () => openHotkeyTarget('reply-all'),
replyAllToFocusedMessage: () => openHotkeyTarget('reply-all'),
forwardFocusedMessage: () => openHotkeyTarget('forward'),
blockSender: context.blockSender,
- markDone: context.archiveThread,
+ markDone,
markNotDone: context.markThreadNotDone,
isThreadDone: context.isThreadDone,
canMarkNotDone: context.canMarkThreadNotDone,
diff --git a/apps/web/src/features/email-view/components/EmailDetailView.tsx b/apps/web/src/features/email-view/components/EmailDetailView.tsx
new file mode 100644
index 0000000000..4f6a8f212d
--- /dev/null
+++ b/apps/web/src/features/email-view/components/EmailDetailView.tsx
@@ -0,0 +1,215 @@
+import { useEntityDetailNavigationStack } from '@app/components/entity-detail/EntityDetailNavigationStack';
+import { ViewBreadcrumbs } from '@app/components/view-shell';
+import { displaySubject } from '@app/features/email-compose/core/subject-text';
+import type { EmailThreadHost } from '@app/features/email-thread/context/email-thread-context';
+import { useBlockEntityCommands } from '@app/features/next-soup/actions';
+import { EmailThreadLoadGate } from '@block-email/component/EmailThreadLoadGate';
+import { EmailThreadHostView } from '@block-email/EmailThreadHostView';
+import { registerEmailHotkeys } from '@block-email/util/emailHotkeys';
+import { useGlobalNotificationSource } from '@components/app/GlobalAppState';
+import { SidePanel } from '@components/app/side-panel';
+import {
+ useCanAutofocusSplitContent,
+ useSplitPanelOrThrow,
+} from '@components/app/split-layout/layoutUtils';
+import { SplitPanel } from '@components/app/split-panel';
+import { EntityIcon } from '@core/component/EntityIcon';
+import { toEntityLoadError } from '@core/component/EntityLoadGate';
+import {
+ ShareDialogContext,
+ ShareTrigger,
+} from '@core/component/TopBar/ShareButton';
+import { ENABLE_EMAIL_SHARING } from '@core/constant/featureFlags';
+import { TOKENS } from '@core/hotkey/tokens';
+import { registerScopeSignalHotkey } from '@core/hotkey/utils';
+import { isTouchDevice } from '@core/mobile/isTouchDevice';
+import { buildEntityData } from '@entity';
+import { useThreadQuery } from '@queries/email/thread';
+import { representativeThreadMessage } from '@queries/email/thread-subject';
+import { createEffect, createMemo, createSignal, Show } from 'solid-js';
+import { useEmailView } from '../email-view-context';
+import type { EmailThreadTarget } from '../types';
+import { useEmailDetailListNavigation } from '../use-email-detail-list-navigation';
+
+function EmailThreadBreadcrumb(props: {
+ value: string;
+ title: string;
+ threadId: string;
+ focusThread: () => void;
+}) {
+ return (
+ <ViewBreadcrumbs.Item
+ value={props.value}
+ metadata={{ type: 'email', id: props.threadId }}
+ order={1}
+ >
+ {(item) => (
+ <ViewBreadcrumbs.Button
+ class="gap-1.5"
+ isActive={item.isActive()}
+ onClick={() => {
+ item.onSelect();
+ props.focusThread();
+ }}
+ >
+ <EntityIcon targetType="email" size="xs" class="shrink-0" />
+ <span class="truncate">{props.title}</span>
+ </ViewBreadcrumbs.Button>
+ )}
+ </ViewBreadcrumbs.Item>
+ );
+}
+
+export function EmailDetailView(props: { thread: EmailThreadTarget }) {
+ const { closeThread } = useEmailView();
+ const navigationStack = useEntityDetailNavigationStack();
+ const panel = useSplitPanelOrThrow();
+ const notificationSource = useGlobalNotificationSource();
+ const canAutofocus = useCanAutofocusSplitContent();
+ const [shareOpen, setShareOpen] = createSignal(false);
+ const threadId = () => props.thread.id;
+ const threadQuery = useThreadQuery(threadId, () => ({
+ enabled: !!threadId(),
+ }));
+ const threadData = createMemo(
+ (previous: typeof threadQuery.data | undefined) =>
+ threadQuery.isSuccess || threadQuery.isError ? threadQuery.data : previous
+ );
+ const title = () => {
+ const thread = threadData()?.thread;
+ return (
+ (thread &&
+ displaySubject(
+ representativeThreadMessage(thread.messages)?.subject
+ )) ||
+ props.thread.fallbackName ||
+ 'Email'
+ );
+ };
+ const commandEntity = createMemo(() => {
+ if (!threadQuery.isSuccess) return undefined;
+ const thread = threadQuery.data?.thread;
+ if (!thread) return undefined;
+ return buildEntityData({
+ id: thread.db_id,
+ name: displaySubject(
+ representativeThreadMessage(thread.messages)?.subject
+ ),
+ blockName: 'email',
+ isRead: thread.is_read,
+ done: !thread.inbox_visible,
+ });
+ });
+ useBlockEntityCommands({
+ id: props.thread.id,
+ scopeId: panel.splitHotkeyScope,
+ resolveEntity: commandEntity,
+ onDeleted: closeThread,
+ });
+
+ let container: HTMLDivElement | undefined;
+ const focusContainer = () => container?.focus({ preventScroll: true });
+ let focused = false;
+ createEffect(() => {
+ if (focused || !canAutofocus || isTouchDevice() || !container) return;
+ focusContainer();
+ focused = true;
+ });
+ const listNavigation = useEmailDetailListNavigation(threadId);
+ const hotkeyScope = () => panel.splitHotkeyScope;
+ const host: EmailThreadHost = {
+ listNavigation,
+ focusContainer,
+ isActive: panel.isPanelActive,
+ registerKeyboard: (handlers) => {
+ registerEmailHotkeys(hotkeyScope(), handlers);
+ registerScopeSignalHotkey(hotkeyScope, {
+ hotkey: 'enter',
+ description: 'Reply to message',
+ keyDownHandler: handlers.activate,
+ hotkeyToken: TOKENS.block.focus,
+ hide: true,
+ });
+ registerScopeSignalHotkey(hotkeyScope, {
+ hotkey: 'escape',
+ description: 'Collapse or unselect message',
+ keyDownHandler: handlers.cancel,
+ hotkeyToken: TOKENS.email.cancelReply,
+ hide: true,
+ });
+ },
+ };
+ const threadEntry = () =>
+ navigationStack.entries.find(
+ (entry) =>
+ entry.data.type === 'email' && entry.data.id === props.thread.id
+ );
+ const breadcrumbValue = () => threadEntry()?.value ?? 'email-view';
+ const loadResult = {
+ data: threadData,
+ error: () =>
+ threadQuery.isError ? toEntityLoadError(threadQuery.error) : undefined,
+ isPending: () => threadQuery.isLoading,
+ };
+
+ return (
+ <ShareDialogContext.Provider
+ value={{
+ isOpen: shareOpen,
+ open: () => setShareOpen(true),
+ close: () => setShareOpen(false),
+ }}
+ >
+ <EmailThreadBreadcrumb
+ value={breadcrumbValue()}
+ title={title()}
+ threadId={props.thread.id}
+ focusThread={focusContainer}
+ />
+ <SidePanel.Root defaultOpen={false}>
+ <div class="flex size-full min-h-0 min-w-0 flex-col overflow-hidden">
+ <div class="flex h-12 min-w-0 shrink-0 items-center gap-1 border-edge border-b px-3">
+ <SplitPanel.CloseButton class="hidden shrink-0 @max-[720px]/view-shell:flex" />
+ <ViewBreadcrumbs.Outlet
+ class="flex-1"
+ aria-label="Email location"
+ />
+ <div class="ml-auto flex shrink-0 items-center gap-2">
+ <Show when={ENABLE_EMAIL_SHARING}>
+ <ShareTrigger
+ id={props.thread.id}
+ blockType="email"
+ hotkeyScope={panel.splitHotkeyScope}
+ />
+ </Show>
+ <SidePanel.Toggle />
+ </div>
+ </div>
+ <div
+ ref={container}
+ class="relative min-h-0 min-w-0 flex-1"
+ tabIndex={-1}
+ >
+ <EmailThreadLoadGate
+ result={loadResult}
+ notificationSource={notificationSource}
+ threadId={props.thread.id}
+ linkId={threadData()?.thread?.link_id}
+ debounceTime={100}
+ onRetry={() => void threadQuery.refetch()}
+ >
+ <EmailThreadHostView
+ title={title()}
+ threadId={threadId}
+ host={host}
+ sidePanelHeaderToggle={false}
+ shareOpen={shareOpen()}
+ onShareOpenChange={setShareOpen}
+ />
+ </EmailThreadLoadGate>
+ </div>
+ </div>
+ </SidePanel.Root>
+ </ShareDialogContext.Provider>
+ );
+}
diff --git a/apps/web/src/features/email-view/components/EmailHeader.tsx b/apps/web/src/features/email-view/components/EmailHeader.tsx
index ed780fea7e..4fba1ff97d 100644
--- a/apps/web/src/features/email-view/components/EmailHeader.tsx
+++ b/apps/web/src/features/email-view/components/EmailHeader.tsx
@@ -1,6 +1,7 @@
import {
SearchBar,
useViewControlHotkeys,
+ ViewBreadcrumbs,
ViewShell,
} from '@app/components/view-shell';
import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
@@ -21,18 +22,34 @@ export type EmailHeaderProps = {
onSearchEscape?: () => void;
};
-export function EmailTopBar() {
+export function EmailViewBreadcrumbItem() {
const { state } = useEmailView();
const tabTitle = () =>
EMAIL_TABS.find((tab) => tab.id === state.tab)?.label ?? 'Email';
+ return (
+ <ViewBreadcrumbs.Item
+ value="email-view"
+ metadata={{ type: 'email-view' }}
+ order={0}
+ >
+ {(item) => (
+ <ViewBreadcrumbs.Button
+ isActive={item.isActive()}
+ onClick={item.onSelect}
+ >
+ <span class="truncate">{tabTitle()}</span>
+ </ViewBreadcrumbs.Button>
+ )}
+ </ViewBreadcrumbs.Item>
+ );
+}
+
+export function EmailTopBar() {
return (
<ViewShell.TopBar class="px-3">
<SplitPanel.CloseButton class="hidden shrink-0 @max-[720px]/view-shell:flex" />
- <h1 class="min-w-0 truncate text-sm font-semibold tracking-[-0.03em] text-ink">
- <span class="@max-[720px]/view-shell:hidden">{tabTitle()}</span>
- <span class="hidden @max-[720px]/view-shell:inline">Email</span>
- </h1>
+ <ViewBreadcrumbs.Outlet class="flex-1" aria-label="Email location" />
</ViewShell.TopBar>
);
}
diff --git a/apps/web/src/features/email-view/components/EmailList.tsx b/apps/web/src/features/email-view/components/EmailList.tsx
index 5fc524e6f0..920d71476e 100644
--- a/apps/web/src/features/email-view/components/EmailList.tsx
+++ b/apps/web/src/features/email-view/components/EmailList.tsx
@@ -36,7 +36,6 @@ import {
import CaretDownIcon from '@phosphor/caret-down.svg';
import CheckIcon from '@phosphor/check.svg';
import SpinnerIcon from '@phosphor/spinner.svg';
-import { useTagSets, useTagSetsReady } from '@property/tags/tag-sets-context';
import { createElementSize } from '@solid-primitives/resize-observer';
import { debounce } from '@solid-primitives/scheduled';
import { Button, cn } from '@ui';
@@ -63,10 +62,7 @@ import {
DEFAULT_EMAIL_LIST_STATE,
type EmailListStateSnapshot,
} from '../persistence';
-import {
- type EmailDataSourceItem,
- useEmailDataSource,
-} from '../queries/use-email-query';
+import type { EmailDataSourceItem } from '../queries/use-email-query';
import { useEmailListHotkeys } from '../use-email-list-hotkeys';
import { EmailDateGroupHeader } from './EmailDateGroupHeader';
import { EmailEmptyState } from './EmailEmptyState';
@@ -87,15 +83,10 @@ export type EmailListProps = {
};
export function EmailList(props: EmailListProps) {
- const { state, setOpenThreadId } = useEmailView();
+ const { state, source, listFocusTarget, clearListFocusTarget, openThread } =
+ useEmailView();
const panel = useSplitPanelOrThrow();
- const tagSets = useTagSets();
- const tagSetsReady = useTagSetsReady();
- const source = withSplitPanelOwner(listOwnedSlotName('data-source'), () =>
- useEmailDataSource(state, { tagSets, tagSetsReady })
- );
-
function openEntity(
entity: EntityData,
options: {
@@ -105,8 +96,6 @@ export function EmailList(props: EmailListProps) {
mergeHistory?: boolean;
} = {}
) {
- if (entity.type === 'email') setOpenThreadId(entity.id);
-
const finishTouchHighlight = options.event
? persistSoupNavigationTouchHighlight(options.event)
: undefined;
@@ -147,6 +136,18 @@ export function EmailList(props: EmailListProps) {
const newSplit =
metadata?.newSplit === true || metadata?.event?.shiftKey === true;
+ if (
+ !newSplit &&
+ metadata?.event?.altKey !== true &&
+ !panel.handle.isControllerSplit()
+ ) {
+ openThread({
+ id: sourceRow.entity.id,
+ fallbackName: sourceRow.entity.name,
+ });
+ return;
+ }
+
openEntity(sourceRow.entity, {
event: metadata?.event,
openInNewSplit: newSplit,
@@ -167,6 +168,18 @@ export function EmailList(props: EmailListProps) {
})
);
+ createEffect(() => {
+ const target = listFocusTarget();
+ if (!target) return;
+ const row = source
+ .items()
+ .find((item) => item.kind === 'entity' && item.entity.id === target);
+ if (!row) return;
+ list.focus.set(row.id, { reason: 'programmatic', force: true });
+ list.selection.setAnchor(row.id);
+ clearListFocusTarget();
+ });
+
withSplitPanelOwner(listOwnedSlotName('navigation-hotkeys'), () => {
useSoupListNavigationHotkeys({
splitHotkeyScope: panel.splitHotkeyScope,
diff --git a/apps/web/src/features/email-view/email-view-context.tsx b/apps/web/src/features/email-view/email-view-context.tsx
index c580e72db9..7e97819877 100644
--- a/apps/web/src/features/email-view/email-view-context.tsx
+++ b/apps/web/src/features/email-view/email-view-context.tsx
@@ -1,13 +1,22 @@
+import {
+ createEntityDetailTarget,
+ useEntityDetailNavigationStack,
+} from '@app/components/entity-detail/EntityDetailNavigationStack';
+import { listOwnedSlotName } from '@app/components/list';
import { setSidebarSectionCollapsed } from '@app/components/view-shell';
import { registerInboxFilterSplit } from '@app/features/next-soup/soup-view/inbox-filter-controllers';
import { normalizeFacetSelection } from '@app/features/soup';
import { makePersistedState } from '@app/lib/persistence';
import { usePreference } from '@app/lib/preferences/use-preference';
-import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
+import {
+ useSplitPanelOrThrow,
+ withSplitPanelOwner,
+} from '@components/app/split-layout/layoutUtils';
import { createAssertedContextProvider } from '@core/context/createContext';
import { useUserId } from '@core/context/user';
+import { useTagSets, useTagSetsReady } from '@property/tags/tag-sets-context';
import type { ContextProviderProps } from '@solid-primitives/context';
-import { type Accessor, onCleanup, type Setter } from 'solid-js';
+import { type Accessor, createSignal, onCleanup, type Setter } from 'solid-js';
import {
createStore,
produce,
@@ -17,7 +26,16 @@ import {
} from 'solid-js/store';
import { DEFAULT_EMAIL_TAB } from './constants';
import { createEmailViewPersistence } from './persistence';
-import type { EmailTab, EmailViewState, EmailViewStateOptions } from './types';
+import {
+ type EmailDataSource,
+ useEmailDataSource,
+} from './queries/use-email-query';
+import type {
+ EmailTab,
+ EmailThreadTarget,
+ EmailViewState,
+ EmailViewStateOptions,
+} from './types';
type EmailViewProviderProps = ContextProviderProps & {
initialState?: EmailViewStateOptions;
@@ -34,7 +52,12 @@ export type EmailViewContext = {
* lands on the All tab. Clearing keeps the current tab.
*/
showTags: (tagIds: string[]) => void;
- setOpenThreadId: (threadId: string | undefined) => void;
+ source: EmailDataSource;
+ selectedThread: Accessor<EmailThreadTarget | undefined>;
+ listFocusTarget: Accessor<string | undefined>;
+ clearListFocusTarget: () => void;
+ openThread: (thread: EmailThreadTarget) => void;
+ closeThread: () => void;
isSidebarSectionOpen: (id: string) => boolean;
setSidebarSectionOpen: (id: string, open: boolean) => void;
/**
@@ -51,7 +74,10 @@ export const [EmailViewProvider, useEmailView] = createAssertedContextProvider<
EmailViewProviderProps
>('EmailView', (props) => {
const panel = useSplitPanelOrThrow();
+ const navigationStack = useEntityDetailNavigationStack();
const userId = useUserId();
+ const tagSets = useTagSets();
+ const tagSetsReady = useTagSetsReady();
const initial = props.initialState ?? {};
const [previewOpen, setPreviewOpen] = usePreference<boolean>(
'macro:pref:soup:mail:preview-open',
@@ -79,9 +105,47 @@ export const [EmailViewProvider, useEmailView] = createAssertedContextProvider<
})
);
+ const source = withSplitPanelOwner(listOwnedSlotName('data-source'), () =>
+ useEmailDataSource(state, { tagSets, tagSetsReady })
+ );
+ const [listFocusTarget, setListFocusTarget] = createSignal<string>();
+
+ const selectedThread = (): EmailThreadTarget | undefined => {
+ const entry = navigationStack.entries.find(
+ (candidate) => candidate.data.type === 'email'
+ );
+ if (!entry || entry.data.type !== 'email') return undefined;
+ return {
+ id: entry.data.id,
+ fallbackName: entry.data.fallbackName,
+ };
+ };
+
+ const openThread = (thread: EmailThreadTarget) => {
+ setListFocusTarget(thread.id);
+ setState('openThreadId', thread.id);
+ navigationStack.reset(
+ createEntityDetailTarget(
+ { type: 'email', id: thread.id },
+ thread.fallbackName
+ )
+ );
+ };
+
+ const closeThread = () => {
+ setState('openThreadId', undefined);
+ navigationStack.clear();
+ };
+
+ if (state.openThreadId) {
+ openThread({ id: state.openThreadId });
+ }
+
// A tab is a fresh slice of the mailbox: filters chosen for one tab (Done
// on Signal, say) would silently narrow the next, so they reset with it.
const setTab = (tab: EmailTab) => {
+ closeThread();
+ setListFocusTarget();
if (state.tab === tab) return;
setState(
@@ -92,16 +156,23 @@ export const [EmailViewProvider, useEmailView] = createAssertedContextProvider<
);
};
- const setInboxIds = (ids: string[] | undefined) =>
+ const setInboxIds = (ids: string[] | undefined) => {
+ closeThread();
+ setListFocusTarget();
setState('inboxIds', ids === undefined ? undefined : [...ids]);
+ };
const setFacets = (facets: EmailViewState['facets']) => {
+ closeThread();
+ setListFocusTarget();
setState('facets', reconcile(normalizeFacetSelection(facets)));
};
// A tag reaches across every mailbox slice, so choosing one from a narrower
// tab moves to All; as with `setTab`, that move drops the tab's other filters.
const showTags = (tagIds: string[]) => {
+ closeThread();
+ setListFocusTarget();
setState(
produce((draft) => {
const movesToAll = tagIds.length > 0 && draft.tab !== 'all';
@@ -114,9 +185,6 @@ export const [EmailViewProvider, useEmailView] = createAssertedContextProvider<
);
};
- const setOpenThreadId = (threadId: string | undefined) =>
- setState('openThreadId', threadId);
-
const isSidebarSectionOpen = (id: string) =>
!state.collapsedSidebarSectionIds.includes(id);
@@ -143,7 +211,12 @@ export const [EmailViewProvider, useEmailView] = createAssertedContextProvider<
setInboxIds,
setFacets,
showTags,
- setOpenThreadId,
+ source,
+ selectedThread,
+ listFocusTarget,
+ clearListFocusTarget: () => setListFocusTarget(),
+ openThread,
+ closeThread,
isSidebarSectionOpen,
setSidebarSectionOpen,
previewOpen,
diff --git a/apps/web/src/features/email-view/email-view.tsx b/apps/web/src/features/email-view/email-view.tsx
index c05fb7348b..410f9899d1 100644
--- a/apps/web/src/features/email-view/email-view.tsx
+++ b/apps/web/src/features/email-view/email-view.tsx
@@ -1,4 +1,8 @@
-import { ViewShell } from '@app/components/view-shell';
+import {
+ EntityDetailNavigationStack,
+ useEntityDetailNavigationStack,
+} from '@app/components/entity-detail/EntityDetailNavigationStack';
+import { ViewBreadcrumbs, ViewShell } from '@app/components/view-shell';
import { type PillTabItem, PillTabs } from '@components/app/mobile/PillTabs';
import { SplitHeaderLeft } from '@components/app/split-layout/components/SplitHeader';
import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
@@ -9,13 +13,20 @@ import { ListEntityMetadataQueryProvider } from '@entity';
import SpinnerIcon from '@phosphor/spinner.svg';
import {
createSignal,
+ Match,
onMount,
type ParentProps,
Show,
Suspense,
+ Switch,
} from 'solid-js';
+import { EmailDetailView } from './components/EmailDetailView';
import { EmailFilterDrawer } from './components/EmailFilterDrawer';
-import { EmailHeader, EmailTopBar } from './components/EmailHeader';
+import {
+ EmailHeader,
+ EmailTopBar,
+ EmailViewBreadcrumbItem,
+} from './components/EmailHeader';
import { EmailList } from './components/EmailList';
import { EmailSidebar } from './components/EmailSidebar';
import { EMAIL_TABS } from './constants';
@@ -27,6 +38,27 @@ export type EmailViewProps = {
initialState?: EmailViewStateOptions;
};
+function EmailViewBreadcrumbs(props: ParentProps) {
+ const { closeThread } = useEmailView();
+ const navigationStack = useEntityDetailNavigationStack();
+
+ return (
+ <ViewBreadcrumbs.Root
+ value={navigationStack.active()?.value ?? 'email-view'}
+ onChange={(value) => {
+ if (value === 'email-view') {
+ closeThread();
+ return;
+ }
+ navigationStack.popTo(value);
+ }}
+ >
+ <EmailViewBreadcrumbItem />
+ {props.children}
+ </ViewBreadcrumbs.Root>
+ );
+}
+
function EmailListFallback() {
return (
<div class="grid size-full min-h-0 min-w-0 place-items-center text-ink-muted touch:pt-(--mobile-content-inset-top) touch:pb-(--mobile-content-inset-bottom)">
@@ -38,6 +70,8 @@ function EmailListFallback() {
function EmailDesktopLayout(
props: ParentProps<{ onSearchEscape: () => void }>
) {
+ const { selectedThread } = useEmailView();
+
return (
<ViewShell.Root
resizable
@@ -48,11 +82,18 @@ function EmailDesktopLayout(
<EmailSidebar />
</ViewShell.Aside>
<ViewShell.Main>
- <EmailTopBar />
- <ViewShell.Header>
- <EmailHeader onSearchEscape={props.onSearchEscape} />
- </ViewShell.Header>
- <ViewShell.Content>{props.children}</ViewShell.Content>
+ <Switch>
+ <Match when={selectedThread()}>
+ {(thread) => <EmailDetailView thread={thread()} />}
+ </Match>
+ <Match when={true}>
+ <EmailTopBar />
+ <ViewShell.Header>
+ <EmailHeader onSearchEscape={props.onSearchEscape} />
+ </ViewShell.Header>
+ <ViewShell.Content>{props.children}</ViewShell.Content>
+ </Match>
+ </Switch>
</ViewShell.Main>
</ViewShell.Root>
);
@@ -96,6 +137,7 @@ function EmailMobileLayout(props: ParentProps) {
function EmailViewRoot() {
const panel = useSplitPanelOrThrow();
+ const { selectedThread } = useEmailView();
const [listElement, setListElement] = createSignal<HTMLDivElement>();
onMount(() => panel.handle.setDisplayName('Email'));
@@ -107,34 +149,45 @@ function EmailViewRoot() {
);
return (
- <ListEntityMetadataQueryProvider>
- <StaticMarkdownContext>
- <SplitPanel.Root>
- <SplitPanel.Body>
- <Show
- when={isTouchDevice()}
- fallback={
- <EmailDesktopLayout
- onSearchEscape={() => listElement()?.focus()}
- >
- {list()}
- </EmailDesktopLayout>
- }
- >
- <EmailMobileLayout>{list()}</EmailMobileLayout>
- </Show>
- </SplitPanel.Body>
- </SplitPanel.Root>
- </StaticMarkdownContext>
- </ListEntityMetadataQueryProvider>
+ <StaticMarkdownContext>
+ <SplitPanel.Root>
+ <SplitPanel.Body>
+ <Show
+ when={isTouchDevice()}
+ fallback={
+ <EmailDesktopLayout onSearchEscape={() => listElement()?.focus()}>
+ {list()}
+ </EmailDesktopLayout>
+ }
+ >
+ <Switch>
+ <Match when={selectedThread()}>
+ {(thread) => <EmailDetailView thread={thread()} />}
+ </Match>
+ <Match when={true}>
+ <EmailMobileLayout>{list()}</EmailMobileLayout>
+ </Match>
+ </Switch>
+ </Show>
+ </SplitPanel.Body>
+ </SplitPanel.Root>
+ </StaticMarkdownContext>
);
}
/** Email shares one list across desktop sidebar and mobile pill layouts. */
export function EmailView(props: EmailViewProps) {
return (
- <EmailViewProvider initialState={props.initialState}>
- <EmailViewRoot />
- </EmailViewProvider>
+ <EntityDetailNavigationStack.Root
+ shouldNavigate={(_, options) => options?.event?.shiftKey !== true}
+ >
+ <ListEntityMetadataQueryProvider>
+ <EmailViewProvider initialState={props.initialState}>
+ <EmailViewBreadcrumbs>
+ <EmailViewRoot />
+ </EmailViewBreadcrumbs>
+ </EmailViewProvider>
+ </ListEntityMetadataQueryProvider>
+ </EntityDetailNavigationStack.Root>
);
}
diff --git a/apps/web/src/features/email-view/types.ts b/apps/web/src/features/email-view/types.ts
index a6981a69f2..eae5dba7aa 100644
--- a/apps/web/src/features/email-view/types.ts
+++ b/apps/web/src/features/email-view/types.ts
@@ -43,8 +43,8 @@ export type EmailViewState = {
inboxIds: string[] | undefined;
facets: FacetSelection;
/**
- * The thread last opened from this view. Restored into the preview on the
- * next visit, the way the Channels view reopens its selected channel.
+ * The thread last opened from this view. Restored into the in-view detail on
+ * the next visit, the way the Channels view reopens its selected channel.
*/
openThreadId?: string;
/** Sidebar sections the user folded away; kept per user, not per visit. */
@@ -52,3 +52,8 @@ export type EmailViewState = {
};
export type EmailViewStateOptions = Partial<EmailViewState>;
+
+export type EmailThreadTarget = {
+ id: string;
+ fallbackName?: string;
+};
diff --git a/apps/web/src/features/email-view/use-email-detail-list-navigation.ts b/apps/web/src/features/email-view/use-email-detail-list-navigation.ts
new file mode 100644
index 0000000000..fcc21e59cd
--- /dev/null
+++ b/apps/web/src/features/email-view/use-email-detail-list-navigation.ts
@@ -0,0 +1,97 @@
+import type {
+ EmailThreadCommands,
+ EmailThreadListNavigation,
+} from '@app/features/email-thread/context/email-thread-context';
+import { adjacentEmail } from '@app/features/email-thread/core/adjacent-email';
+import { toast } from '@core/component/Toast/Toast';
+import type { EntityData } from '@entity';
+import { type Accessor, createSignal, onCleanup } from 'solid-js';
+import { useEmailView } from './email-view-context';
+
+/** Keeps thread triage inside the Email view's filtered navigation stack. */
+export function useEmailDetailListNavigation(
+ threadId: Accessor<string>
+): EmailThreadListNavigation {
+ const { source, openThread } = useEmailView();
+ const [navigating, setNavigating] = createSignal(false);
+ let disposed = false;
+ onCleanup(() => {
+ disposed = true;
+ });
+ const isCurrent = (id: string) => !disposed && threadId() === id;
+
+ const entities = (): EntityData[] =>
+ source
+ .items()
+ .flatMap((row) => (row.kind === 'entity' ? [row.entity] : []));
+ const target = (direction: -1 | 1) =>
+ adjacentEmail(entities(), threadId(), direction);
+ const canLoadNext = () =>
+ source.hasMore() &&
+ entities().some(
+ (entity) => entity.type === 'email' && entity.id === threadId()
+ );
+ const open = (entity: EntityData) => {
+ if (entity.type !== 'email') return;
+ openThread({ id: entity.id, fallbackName: entity.name });
+ };
+
+ const navigate = async (
+ direction: -1 | 1,
+ archiveThread?: EmailThreadCommands['archiveThread']
+ ) => {
+ if (disposed || navigating()) return;
+ setNavigating(true);
+ const currentId = threadId();
+ const current = entities().find(
+ (entity) => entity.type === 'email' && entity.id === currentId
+ );
+
+ try {
+ while (direction === 1 && !target(direction) && canLoadNext()) {
+ await source.loadMore();
+ if (!isCurrent(currentId)) return;
+ }
+ if (!isCurrent(currentId)) return;
+
+ const next =
+ target(direction) ?? (archiveThread ? target(-1) : undefined);
+ if (
+ archiveThread &&
+ !archiveThread({
+ navigate: false,
+ nextEntityId: next?.id,
+ navigateBack:
+ current && next
+ ? () => {
+ open(current);
+ }
+ : undefined,
+ })
+ ) {
+ return;
+ }
+ if (next) open(next);
+ } catch {
+ if (isCurrent(currentId)) {
+ toast.failure('Unable to open the next or previous email');
+ }
+ } finally {
+ setNavigating(false);
+ }
+ };
+
+ return {
+ canPrevious: () => !navigating() && !!target(-1),
+ canNext: () => !navigating() && (!!target(1) || canLoadNext()),
+ previous: () => {
+ void navigate(-1);
+ },
+ next: () => {
+ void navigate(1);
+ },
+ markDone: (archiveThread) => {
+ void navigate(1, archiveThread);
+ },
+ };
+}
diff --git a/apps/web/src/lib/core/component/TopBar/ShareButton.tsx b/apps/web/src/lib/core/component/TopBar/ShareButton.tsx
index 42dc1dffb3..59e6dd05a8 100644
--- a/apps/web/src/lib/core/component/TopBar/ShareButton.tsx
+++ b/apps/web/src/lib/core/component/TopBar/ShareButton.tsx
@@ -1391,10 +1391,18 @@ export function ShareTrigger(props: {
const shareCtx = useShareDialogContext();
const isAuthenticated = useIsAuthenticated();
const inBlock = isInBlock();
- const contextualBlockType = inBlock
- ? useBlockAliasedName()
- : useMaybeBlockAliasedName();
- const contextualBlockId = inBlock ? useBlockId() : useMaybeBlockId();
+ const contextualBlockType =
+ props.blockType === undefined
+ ? inBlock
+ ? useBlockAliasedName()
+ : useMaybeBlockAliasedName()
+ : undefined;
+ const contextualBlockId =
+ props.id === undefined
+ ? inBlock
+ ? useBlockId()
+ : useMaybeBlockId()
+ : undefined;
const analytics = useAnalytics();
const blockType = (): BlockName | BlockAlias => {
diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.md
index d1dc8019d7..5632af1470 100644
--- a/docs/AGENT_GUIDE/surfaces.md
+++ b/docs/AGENT_GUIDE/surfaces.md
@@ -278,9 +278,13 @@ The first scenario covers Signal → Noise → All after disconnecting both nati
HTTP and WebSockets. iOS shares the native cache code but is not yet covered by
that driver.
-Threads open at `/app/email/<thread-id>`. Click a message header to expand or
-collapse it; `Show N hidden messages` reveals the collapsed middle of a longer
-conversation. A link with `?email_message_id=<message-id>` reveals that message.
+In the new Email view, ordinary row activation opens the thread inside
+`/app/component/mail`; the Email breadcrumb returns to the filtered list.
+Shift-click opens a standalone split at `/app/email/<thread-id>`, which remains
+the destination for direct links and legacy surfaces. Click a message header to
+expand or collapse it; `Show N hidden messages` reveals the collapsed middle of
+a longer conversation. A standalone link with
+`?email_message_id=<message-id>` reveals that message.
Collapsed thread cards use a compact text snippet; expanding mounts the message
body and its attachments. On phones, messages form flat rows with horizontal
separators and 16px side gutters; collapsed previews show one line. Desktop
@@ -620,9 +624,10 @@ They do not wrap; a thread opened without a source list has disabled arrows.
Mark done archives the current thread and opens the next email in that same
filtered list, loading pages until another email is found or the list ends.
On native mobile, stepping replaces the current email while preserving the
-filtered list behind it for swipe-back. This works with both the legacy mobile
-list and the newer app views. To verify, open the first email from Signal or
-Noise, tap Next and then Previous, and swipe back to the same filtered list.
+filtered list behind it for swipe-back. In the newer Email view it retargets the
+view-owned detail stack instead of opening another block. To verify, open the
+first email from Signal or Noise, tap Next and then Previous, and return to the
+same filtered list.
Leaving the email cancels pending
navigation and archiving while a page loads. At the end it opens the previous
email; with no neighboring email it stays on the archived thread. Mark as not done
diff --git a/docs/EMAIL_FEATURE_ARCHITECTURE.md b/docs/EMAIL_FEATURE_ARCHITECTURE.md
index 6cfbd71bfb..a0ad83d686 100644
--- a/docs/EMAIL_FEATURE_ARCHITECTURE.md
+++ b/docs/EMAIL_FEATURE_ARCHITECTURE.md
@@ -14,7 +14,7 @@ same application routes.
| `email-message` | A received or sent message, its sender/header, body renderer lifecycle and policy, Macro Markdown, quote expansion controls, and attachment presentation | Thread ordering, pagination, selection policy, drafts, reply placement, navigation, block state |
| `email-thread` | A conversation, chronological ordering, hidden middle messages, pagination, draft association, reading stops, selection, scroll coordination, and where a reply appears | Rendering the internals of an email, editing or sending a draft, block lifecycle |
| `email-compose` | Form state, recipient rules, editor content, attachments, draft persistence, sending, scheduling, signatures, and undo recovery | Thread pagination/rendering, block identity, app routes or split navigation |
-| `block-email` | The document-block host: load gate, read marker, block hotkeys/focus, location registration, header, modals, side panel, and host actions | Reusable thread, message, or composer state |
+| `block-email` | The legacy document-block adapter plus host-neutral thread body shared with the Email view: load gate, read marker, modals, side panel, and host actions | Reusable thread, message, composer state, or a host's top bar |
An email thread and an individual email are independent features. A message can be
rendered without a thread provider. A composer can run without a thread: the
@@ -26,7 +26,9 @@ Dependency arrows mean “imports or consumes”:
```mermaid
flowchart TD
- Block[block-email adapter] --> ThreadRoot[email-thread production entry]
+ Block[block-email adapter] --> HostView[email thread host view]
+ EmailView[email view detail] --> HostView
+ HostView --> ThreadRoot[email-thread production entry]
ThreadRoot --> Thread[email-thread surface and state]
ThreadRoot --> Adapters[production adapters and shared queries]
Thread --> Message[email-message view]
@@ -62,10 +64,18 @@ may import a block package, `@core/block`, or block-related signal modules.
`email-thread/views/thread-reply-input.tsx` owns the keyed reply lifetime;
`email-compose/primitives/reply-composer.ts` owns the compose workflow.
- `block-email/EmailBlockAdapter.tsx` translates block focus, keyboard scope,
- location parameters, and block methods into `EmailThreadHost` callbacks and
- slots. The thread does not read a block ID or register a block method itself.
- The adapter captures block signal accessors during setup; event callbacks use
- those captured functions instead of resolving a provider after setup.
+ location parameters, and block methods into `EmailThreadHost` callbacks.
+ `block-email/EmailThreadHostView.tsx` composes the shared thread body without
+ reading block state, so the Email view can mount it directly and compose its
+ own top bar. The thread does not read a block ID or register a block method
+ itself. The adapter captures block signal accessors during setup; event
+ callbacks use those captured functions instead of resolving a provider after
+ setup.
+- `email-view` owns an `EntityDetailNavigationStack`. Ordinary list activation
+ mounts the thread inside `/app/component/mail`; Shift-open and Preview Pair
+ navigation continue through the standalone `/app/email/:threadId` block. The
+ filtered data source outlives the list UI so Previous, Next, Mark done, and
+ restored list focus keep their source order while detail is mounted.
Capability contracts and provider/consumer modules live in `context/`. Prepared
view-state types live in `primitives/`; views mount the providers.