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(view-shell): full-width Chat and Notifications lists when narrow (#9904)

Peter Chinman98ecb023d54f
diff --git a/apps/web/src/components/view-shell/README.md b/apps/web/src/components/view-shell/README.md
index 8dc97a5175..52fb998a24 100644
--- a/apps/web/src/components/view-shell/README.md
+++ b/apps/web/src/components/view-shell/README.md
@@ -44,3 +44,10 @@ A single host phase (`docked`, `closing`, or `overlay`) controls mounting.
Breakpoint transitions own host changes; pin changes only animate the active
host and do not cancel a pending narrow exit.
Reduced-motion and browsers without WAAPI switch hosts immediately.
+
+A view whose aside is its entity list (Chat, Notifications) passes `asideList`.
+Narrow, it bypasses the overlay: the list fills the shell over an inert Main
+until `open`, then Main fills it and `ViewNavigationControls` shows Back,
+calling `onBack`, in place of Show navigation. The list stays mounted, hidden
+and inert, so it keeps its scroll, and takes focus when Back returns to it.
+Collapse controls and `Cmd+.` are off there; wide layouts are unchanged.
diff --git a/apps/web/src/components/view-shell/ViewShell.test.tsx b/apps/web/src/components/view-shell/ViewShell.test.tsx
index 4d84b5ea52..73ebf8368d 100644
--- a/apps/web/src/components/view-shell/ViewShell.test.tsx
+++ b/apps/web/src/components/view-shell/ViewShell.test.tsx
@@ -278,6 +278,7 @@ function Workspace(props: {
app: string;
asideRequired?: boolean;
asidePinned?: boolean;
+ asideList?: ViewShellRootProps['asideList'];
breakpoints?: ViewShellRootProps['breakpoints'];
mounted?: () => void;
}) {
@@ -299,6 +300,7 @@ function Workspace(props: {
asidePreferenceKey={props.app}
asideRequired={props.asideRequired}
asidePinned={props.asidePinned}
+ asideList={props.asideList}
breakpoints={props.breakpoints}
>
<ViewShell.Aside>
@@ -1127,3 +1129,58 @@ describe('automatic docked navigation exit', () => {
}
);
});
+
+describe('list navigation', () => {
+ const main = () => document.querySelector('[data-view-shell-main]')!;
+ const list = () => document.querySelector('[data-view-shell-aside]')!;
+
+ it('fills a narrow shell with the list until an item opens, then goes back to it', () => {
+ const [width, setWidth] = createSignal(600);
+ measurement.width = width;
+ const [open, setOpen] = createSignal(false);
+ const onBack = vi.fn(() => setOpen(false));
+ render(() => (
+ <Workspace app="channels" asideList={{ open: open(), onBack }} />
+ ));
+
+ expect(screen.getByText('channels')).toBeTruthy();
+ expect(main().getAttribute('aria-hidden')).toBe('true');
+ expect(
+ screen.queryByRole('button', { name: 'Close navigation backdrop' })
+ ).toBeNull();
+ expect(
+ screen.queryByRole('button', { name: 'Hide navigation' })
+ ).toBeNull();
+
+ const listElement = list();
+ setOpen(true);
+ // Hidden, not unmounted, so the list keeps its scroll position.
+ expect(list()).toBe(listElement);
+ expect(list().getAttribute('aria-hidden')).toBe('true');
+ expect(main().getAttribute('aria-hidden')).not.toBe('true');
+ expect(
+ screen.queryByRole('button', { name: 'Show navigation' })
+ ).toBeNull();
+ fireEvent.click(screen.getByRole('button', { name: 'Back' }));
+ expect(onBack).toHaveBeenCalledOnce();
+ expect(list().getAttribute('aria-hidden')).not.toBe('true');
+ expect(document.activeElement).toBe(listElement);
+
+ // Focus handed to the pane around the view also returns to the list.
+ const pane = screen.getByRole('region', { name: 'channels' });
+ pane.tabIndex = -1;
+ setOpen(true);
+ pane.focus();
+ fireEvent.click(screen.getByRole('button', { name: 'Back' }));
+ expect(document.activeElement).toBe(listElement);
+
+ setOpen(true);
+ setWidth(1000);
+ expect(asideDocked()).toBe(true);
+ expect(screen.queryByRole('button', { name: 'Back' })).toBeNull();
+ fireEvent.click(screen.getByRole('button', { name: 'Hide navigation' }));
+ expect(
+ screen.getByRole('button', { name: 'Show navigation' })
+ ).toBeTruthy();
+ });
+});
diff --git a/apps/web/src/components/view-shell/ViewShell.tsx b/apps/web/src/components/view-shell/ViewShell.tsx
index a4b42f0a4f..a4a5fff30f 100644
--- a/apps/web/src/components/view-shell/ViewShell.tsx
+++ b/apps/web/src/components/view-shell/ViewShell.tsx
@@ -1,3 +1,4 @@
+import { t } from '@app/lib/i18n';
import { usePreference } from '@app/preferences/use-preference';
import {
type BreakpointAccessors,
@@ -10,6 +11,7 @@ import { SplitPanel } from '@components/app/split-panel';
import { Resize } from '@core/component/Resize';
import { registerHotkey } from '@core/hotkey/hotkeys';
import { TOKENS } from '@core/hotkey/tokens';
+import ArrowLeftIcon from '@icon/system/regular/arrow-left.svg';
import SidebarIcon from '@icon/system/regular/sidebar-simple.svg';
import CloseIcon from '@icon/system/regular/x.svg';
import { createWritableMemo } from '@solid-primitives/memo';
@@ -23,6 +25,7 @@ import {
type ComponentProps,
createComputed,
createContext,
+ createEffect,
createMemo,
createSignal,
createUniqueId,
@@ -85,6 +88,9 @@ type ViewShellInternal = ViewShellLayout & {
id: string;
atLayoutBreakpoint: Accessor<boolean>;
asideHost: Accessor<'docked' | 'closing' | 'overlay'>;
+ /** Which of a list aside and Main fills a narrow shell; undefined otherwise. */
+ narrowList: Accessor<'list' | 'main' | undefined>;
+ returnToList: () => void;
chooseAsideWidth: (width: number) => void;
};
@@ -155,6 +161,13 @@ export type ViewShellRootProps = Omit<
* overlay closed.
*/
asidePinned?: boolean;
+ /**
+ * For a view whose aside holds its entity list and whose Main shows the
+ * entity open from it. Narrow layouts then show one of them at full width
+ * instead of the navigation overlay: the list until `open`, then Main, with
+ * a back button that calls `onBack` in place of Show navigation.
+ */
+ asideList?: { open: boolean; onBack: () => void };
main?: Partial<MainLayout>;
detail?: Partial<DetailLayout>;
/** Controlled detail open state. Omit for uncontrolled. */
@@ -180,6 +193,7 @@ function Root(props: ViewShellRootProps) {
'asidePreferenceKey',
'asideRequired',
'asidePinned',
+ 'asideList',
'main',
'detail',
'detailOpen',
@@ -285,17 +299,31 @@ function Root(props: ViewShellRootProps) {
// behind a backdrop with no way to dismiss it.
const asidePinned = () =>
(asideRequired() || (local.asidePinned ?? false)) && !atLayoutBreakpoint();
+ // A list aside takes turns with Main in narrow layouts rather than
+ // overlaying it, so the overlay and its open state don't apply there.
+ const narrowList = (): 'list' | 'main' | undefined => {
+ if (!local.asideList || local.aside === false || !atLayoutBreakpoint()) {
+ return undefined;
+ }
+ return local.asideList.open ? 'main' : 'list';
+ };
+
+ const asideMode = (): AsideMode => {
+ const list = narrowList();
+ if (list) return list === 'list' ? 'docked' : 'collapsed';
- const asideMode = (): AsideMode =>
- local.aside === false ||
- (atLayoutBreakpoint()
- ? !narrowAsideOpen()
- : wideAsideCollapsed() && !asidePinned())
+ return local.aside === false ||
+ (atLayoutBreakpoint()
+ ? !narrowAsideOpen()
+ : wideAsideCollapsed() && !asidePinned())
? 'collapsed'
: 'docked';
- const asideOverlay = () => atLayoutBreakpoint() && asideMode() === 'docked';
+ };
+ const asideOverlay = () =>
+ atLayoutBreakpoint() && !narrowList() && asideMode() === 'docked';
const setAsideOpen = (open: boolean) => {
+ if (narrowList()) return;
if (!open && asidePinned()) return;
// Repeated requests must not cancel an exit that still owns host cleanup.
if (open === (asideMode() === 'docked')) return;
@@ -332,6 +360,7 @@ function Root(props: ViewShellRootProps) {
).find((panel) => panel.querySelector('[data-view-shell-aside]'));
const retain =
narrow &&
+ !local.asideList &&
!asideRequired() &&
!!docked &&
!docked.classList.contains('hidden');
@@ -389,6 +418,8 @@ function Root(props: ViewShellRootProps) {
breakpoints,
atLayoutBreakpoint,
asideHost,
+ narrowList,
+ returnToList: () => local.asideList?.onBack(),
chooseAsideWidth: setChosenAsideWidth,
aside: {
layout: asideLayout,
@@ -397,7 +428,8 @@ function Root(props: ViewShellRootProps) {
canCollapse: () =>
local.asidePreferenceKey !== undefined &&
local.aside !== false &&
- !asidePinned(),
+ !asidePinned() &&
+ !narrowList(),
isOverlay: asideOverlay,
collapse: () => setAsideOpen(false),
expand: () => setAsideOpen(true),
@@ -469,6 +501,70 @@ function Root(props: ViewShellRootProps) {
* ViewSidebar.Root inside keeps the landmark.
*/
function Aside(props: JSX.HTMLAttributes<HTMLDivElement>) {
+ const ws = useViewShellInternal();
+ return (
+ <Show when={ws.narrowList()} fallback={<AsideHost {...props} />}>
+ <NarrowListAside {...props} />
+ </Show>
+ );
+}
+
+/**
+ * A narrow list fills the shell over Main, which waits beneath it. While an
+ * entity is open the list stays mounted but hidden, so it keeps its scroll.
+ */
+function NarrowListAside(props: JSX.HTMLAttributes<HTMLDivElement>) {
+ const [local, rest] = splitProps(props, ['children', 'class']);
+ const ws = useViewShellInternal();
+ const asideTarget = tourTarget(VIEW_SHELL_TOUR.aside);
+ const hidden = () => ws.narrowList() === 'main';
+ let list: HTMLDivElement | undefined;
+
+ // Back leaves with the entity it was on; hand focus to the list, unless
+ // the user has already moved it outside this view.
+ createEffect(
+ on(
+ hidden,
+ (isHidden) => {
+ if (isHidden || !list) return;
+ const active = document.activeElement;
+ const shell = list.closest('[data-view-shell]');
+ // Removing a focused scope hands focus to the pane around this view.
+ const focusLost =
+ !active || active === document.body || active.contains(shell);
+ if (!focusLost && !shell?.contains(active)) return;
+ if (list.contains(active)) return;
+
+ list.focus({ preventScroll: true });
+ },
+ { defer: true }
+ )
+ );
+
+ return (
+ <div
+ {...rest}
+ ref={(element) => {
+ list = element;
+ asideTarget(element);
+ }}
+ tabIndex={-1}
+ class={cn(
+ 'absolute inset-0 z-20 min-h-0 bg-panel outline-none',
+ hidden() && 'invisible',
+ local.class
+ )}
+ data-view-shell-aside=""
+ inert={hidden()}
+ aria-hidden={hidden()}
+ >
+ {local.children}
+ </div>
+ );
+}
+
+/** Docked or overlay navigation, whichever the layout hosts. */
+function AsideHost(props: JSX.HTMLAttributes<HTMLDivElement>) {
const [local, rest] = splitProps(props, ['children', 'class']);
const ws = useViewShellInternal();
const asideTarget = tourTarget(VIEW_SHELL_TOUR.aside);
@@ -671,6 +767,24 @@ export function ViewSidebarToggle(props: { action: 'collapse' | 'expand' }) {
);
}
+/** Takes a narrow list view from the open entity back to its list. */
+function ViewListBackButton(props: { onClick: () => void }) {
+ return (
+ <Button
+ aria-label={t('common.back')}
+ tooltip={t('common.back')}
+ variant="ghost"
+ size="icon-xs"
+ class="shrink-0"
+ // The way out of an inline preview is reachable before it is used.
+ data-allow-focus-in-preview
+ onClick={() => props.onClick()}
+ >
+ <ArrowLeftIcon class="size-4" />
+ </Button>
+ );
+}
+
/** Shared leading controls, kept in place beneath navigation overlays. */
export function ViewNavigationControls() {
const ws = useContext(ViewShellContext);
@@ -681,7 +795,12 @@ export function ViewNavigationControls() {
aria-hidden={ws?.aside.isOverlay()}
>
<SplitPanel.CloseButton />
- <ViewSidebarToggle action="expand" />
+ <Show
+ when={ws?.narrowList() === 'main'}
+ fallback={<ViewSidebarToggle action="expand" />}
+ >
+ <ViewListBackButton onClick={() => ws?.returnToList()} />
+ </Show>
</SplitPanel.ControlGroup>
</Show>
);
@@ -723,6 +842,8 @@ function Main(props: ViewShellMainProps) {
ref={mergeRefs(local.ref, tourTarget(VIEW_SHELL_TOUR.main))}
class={cn('flex size-full min-h-0 min-w-0 flex-col', local.class)}
data-view-shell-main=""
+ inert={ws.narrowList() === 'list'}
+ aria-hidden={ws.narrowList() === 'list'}
>
{local.children}
</main>
diff --git a/apps/web/src/features/channels-view/channels-view.tsx b/apps/web/src/features/channels-view/channels-view.tsx
index b5ebddcb96..1edbd18972 100644
--- a/apps/web/src/features/channels-view/channels-view.tsx
+++ b/apps/web/src/features/channels-view/channels-view.tsx
@@ -148,9 +148,21 @@ function DesktopChannelThreads(props: { sources: ChannelsSources }) {
}
function ChannelsViewRoot() {
const panel = useSplitPanelOrThrow();
- const { state, tab, mobileLayout, sectionsLoading, selectedChannel } =
- useChannelsView();
+ const {
+ state,
+ tab,
+ setTab,
+ mobileLayout,
+ sectionsLoading,
+ selectedChannel,
+ setSelectedChannel,
+ } = useChannelsView();
const threadsTab = () => !mobileLayout() && tab() === 'threads';
+ // Threads fill Main like a conversation, so going back leaves them first.
+ const returnToList = () => {
+ if (threadsTab()) setTab('browse');
+ else setSelectedChannel(undefined);
+ };
const [railSearchOpen, setRailSearchOpen] = createSignal(false);
const sources = useChannelsSources(
@@ -192,8 +204,13 @@ function ChannelsViewRoot() {
asidePreferenceKey="channels"
// The empty state only points at the rail, so keep it open.
asideRequired={selectedChannel() === undefined}
- // Keep tab changes from resetting a narrow navigation overlay.
+ // Threads are chosen in the rail's tabs, so keep it docked.
asidePinned={threadsTab()}
+ // Narrow, the rail and the conversation take turns.
+ asideList={{
+ open: selectedChannel() !== undefined || threadsTab(),
+ onBack: returnToList,
+ }}
aside={{ preserveDuringResize: false }}
main={{ preferredWidth: 640 }}
resizable
diff --git a/apps/web/src/features/notifications-inbox/components/notifications-breadcrumb.tsx b/apps/web/src/features/notifications-inbox/components/notifications-breadcrumb.tsx
deleted file mode 100644
index 2d1f58a009..0000000000
--- a/apps/web/src/features/notifications-inbox/components/notifications-breadcrumb.tsx
+++ /dev/null
@@ -1,20 +0,0 @@
-import { ViewBreadcrumbs } from '@app/components/view-shell';
-import { t } from '@app/lib/i18n';
-
-/** The way back from what the content area shows to the notifications list. */
-export function NotificationsBreadcrumb(props: { onReturn: () => void }) {
- return (
- <nav
- aria-label={t('notificationsInbox.location')}
- class="flex items-center gap-0.5"
- >
- <ViewBreadcrumbs.ReturnButton
- data-allow-focus-in-preview
- onClick={props.onReturn}
- >
- {t('nav.notifications')}
- </ViewBreadcrumbs.ReturnButton>
- <ViewBreadcrumbs.Separator />
- </nav>
- );
-}
diff --git a/apps/web/src/features/notifications-inbox/context/notifications-calendar-context.ts b/apps/web/src/features/notifications-inbox/context/notifications-calendar-context.ts
index bc0b99476b..c027222a1d 100644
--- a/apps/web/src/features/notifications-inbox/context/notifications-calendar-context.ts
+++ b/apps/web/src/features/notifications-inbox/context/notifications-calendar-context.ts
@@ -4,8 +4,6 @@ import { type Accessor, createContext, useContext } from 'solid-js';
export type NotificationsCalendarPaneContext = {
/** Bumped when the open event is chosen again, to re-aim at it in place. */
refocus: Accessor<number>;
- /** Close the Calendar and return to the notifications list. */
- onReturn: () => void;
};
const Context = createContext<NotificationsCalendarPaneContext>();
diff --git a/apps/web/src/features/notifications-inbox/inbox-location.ts b/apps/web/src/features/notifications-inbox/inbox-location.ts
new file mode 100644
index 0000000000..d934fc82d4
--- /dev/null
+++ b/apps/web/src/features/notifications-inbox/inbox-location.ts
@@ -0,0 +1,51 @@
+import {
+ createSearchParams,
+ createSearchParamsCodec,
+ type SerializedSearchParams,
+} from '@app/lib/split-router';
+import { z } from 'zod';
+import type {
+ InboxShownRow,
+ InboxShownRowLocation,
+} from './primitives/inbox-selection';
+
+/** The row the Notifications preview shows, so each one opened is a history entry. */
+export const inboxSearch = {
+ namespace: 'inbox',
+ schema: z.object({ row: z.string(), item: z.string() }),
+ defaults: { row: '', item: '' },
+};
+
+const inboxSearchCodec = createSearchParamsCodec(inboxSearch);
+
+/** The search naming `shown`, for a navigation that also leaves or opens the Calendar. */
+export function inboxSearchFor(
+ shown: InboxShownRow
+): Record<string, SerializedSearchParams | undefined> {
+ return { [inboxSearch.namespace]: inboxSearchCodec.serialize(shown) };
+}
+
+/**
+ * Keeps the shown row in the Notifications URL. Leaving an open Calendar for
+ * another row, or for the list, is a single entry.
+ */
+export function useInboxShownRowLocation(calendar: {
+ isOpen: () => boolean;
+ close: (navigation: {
+ search: Record<string, SerializedSearchParams | undefined>;
+ replace: boolean;
+ }) => void;
+}): InboxShownRowLocation {
+ const [search, setSearch] = createSearchParams(inboxSearch);
+
+ return {
+ shown: () => ({ row: search.row, item: search.item }),
+ show: (next, { replace }) => {
+ if (calendar.isOpen()) {
+ calendar.close({ search: inboxSearchFor(next), replace });
+ return;
+ }
+ setSearch(next, { history: replace ? 'replace' : 'push' });
+ },
+ };
+}
diff --git a/apps/web/src/features/notifications-inbox/notifications-calendar-preview.ts b/apps/web/src/features/notifications-inbox/notifications-calendar-preview.ts
index 033135dc81..6cea3314a1 100644
--- a/apps/web/src/features/notifications-inbox/notifications-calendar-preview.ts
+++ b/apps/web/src/features/notifications-inbox/notifications-calendar-preview.ts
@@ -9,6 +9,7 @@ import {
import type { CalendarPreviewSelection } from '@app/features/next-soup/utils';
import {
createSearchParams,
+ type SerializedSearchParams,
useNavigate,
useRouteParams,
} from '@app/lib/split-router';
@@ -26,6 +27,12 @@ import { Telemetry } from '@macro-inc/observability';
import deepEqual from 'fast-deep-equal';
import { createSignal } from 'solid-js';
+/** The rest of the history entry: other search it writes, and whether it replaces. */
+export type CalendarPreviewNavigation = {
+ search?: Record<string, SerializedSearchParams | undefined>;
+ replace?: boolean;
+};
+
/**
* Shows calendar events in the Notifications view's content area: the
* Calendar view under the view's own calendar route, aimed at the event.
@@ -39,7 +46,10 @@ export function useNotificationsCalendarPreview() {
const isOpen = () => typeof params.period === 'string';
/** Aim the inline Calendar at the event; false when it can't show it. */
- const open = (entity: CalendarPreviewSelection) => {
+ const open = (
+ entity: CalendarPreviewSelection,
+ navigation: CalendarPreviewNavigation = {}
+ ) => {
if (!isFeatureEnabled(enableCalendarUi)) return false;
const target = previewCalendarTarget(entity);
if (!target.eventId) return false;
@@ -53,21 +63,29 @@ export function useNotificationsCalendarPreview() {
search,
calendarTargetSearch(calendarSearchTarget(openSearch))
);
+ const period = params.period ?? getPreferredCalendarPeriodView();
if (shown) {
setRefocus((count) => count + 1);
span.setAttr('calendar.destination', 'refocus');
+ // The Calendar keeps its place; only the row that chose it changes.
+ if (navigation.search) {
+ fireAndForget(
+ navigate(
+ { route: notificationsCalendarRoute, params: { period } },
+ { replace: navigation.replace, search: navigation.search }
+ ),
+ 'notifications-inbox'
+ );
+ }
return true;
}
fireAndForget(
navigate(
+ { route: notificationsCalendarRoute, params: { period } },
{
- route: notificationsCalendarRoute,
- params: {
- period: params.period ?? getPreferredCalendarPeriodView(),
- },
- },
- {
+ replace: navigation.replace,
search: {
+ ...navigation.search,
[CALENDAR_SEARCH_NAMESPACE]:
calendarSearchCodec.serialize(search),
},
@@ -83,16 +101,22 @@ export function useNotificationsCalendarPreview() {
};
/** Leave the inline Calendar, when it is open. */
- const close = () => {
+ const close = (navigation: CalendarPreviewNavigation = {}) => {
if (!isOpen()) return;
fireAndForget(
navigate(
{ route: notificationsRoute, params: {} },
- { search: { [CALENDAR_SEARCH_NAMESPACE]: undefined } }
+ {
+ replace: navigation.replace,
+ search: {
+ ...navigation.search,
+ [CALENDAR_SEARCH_NAMESPACE]: undefined,
+ },
+ }
),
'notifications-inbox'
);
};
- return { open, close, refocus };
+ return { open, close, refocus, isOpen };
}
diff --git a/apps/web/src/features/notifications-inbox/notifications-inbox.tsx b/apps/web/src/features/notifications-inbox/notifications-inbox.tsx
index c8b23d3c96..17e0fa708a 100644
--- a/apps/web/src/features/notifications-inbox/notifications-inbox.tsx
+++ b/apps/web/src/features/notifications-inbox/notifications-inbox.tsx
@@ -22,6 +22,7 @@ import {
type NotificationsInboxContext,
NotificationsInboxProvider,
} from './context/notifications-inbox-context';
+import { inboxSearchFor, useInboxShownRowLocation } from './inbox-location';
import { useNotificationsCalendarPreview } from './notifications-calendar-preview';
import { openNotificationInSplit } from './open-notification-in-split';
import { createNotificationInboxSource } from './queries/notification-inbox-source';
@@ -86,6 +87,7 @@ export function NotificationsInbox() {
const { openSettings } = useSettingsState();
const respondToJoinRequest = useRespondToCalendarJoinRequestMutation();
const calendarPreview = useNotificationsCalendarPreview();
+ const shownRow = useInboxShownRowLocation(calendarPreview);
const answerJoinRequest: NotificationsInboxContext['requests']['answerJoinRequest'] =
async (request, accept) => {
await respondToJoinRequest.mutateAsync({
@@ -101,7 +103,16 @@ export function NotificationsInbox() {
>
<NotificationsView
onOpenSettings={() => openSettings('Notifications')}
- calendarPreview={calendarPreview}
+ shownRow={shownRow}
+ calendarPreview={{
+ open: (entity, { shown, replace }) =>
+ calendarPreview.open(entity, {
+ search: inboxSearchFor(shown),
+ replace,
+ }),
+ isOpen: calendarPreview.isOpen,
+ refocus: calendarPreview.refocus,
+ }}
onOpen={(row, { newSplit, notification }) =>
openNotificationInSplit(row, {
newSplit,
diff --git a/apps/web/src/features/notifications-inbox/primitives/inbox-selection.test.ts b/apps/web/src/features/notifications-inbox/primitives/inbox-selection.test.ts
index d0ef7fcdd4..9e26d5799d 100644
--- a/apps/web/src/features/notifications-inbox/primitives/inbox-selection.test.ts
+++ b/apps/web/src/features/notifications-inbox/primitives/inbox-selection.test.ts
@@ -1,7 +1,11 @@
import { createRoot, createSignal } from 'solid-js';
import { describe, expect, it } from 'vitest';
import type { NotificationInboxRow } from '../context/notifications-inbox-context';
-import { createInboxSelection } from './inbox-selection';
+import {
+ createInboxSelection,
+ type InboxShownRow,
+ type InboxShownRowLocation,
+} from './inbox-selection';
const row = (id: string, revision = 'r1'): NotificationInboxRow => ({
id,
@@ -32,10 +36,27 @@ const stack = (
},
});
+/** A URL stand-in that records each write as a history entry. */
+const memoryLocation = (initial: InboxShownRow = { row: '', item: '' }) => {
+ const [shown, setShown] = createSignal(initial);
+ const writes: { next: InboxShownRow; replace: boolean }[] = [];
+ const location: InboxShownRowLocation = {
+ shown,
+ show: (next, { replace }) => {
+ writes.push({ next, replace });
+ setShown(next);
+ },
+ };
+ return { location, writes };
+};
+
describe('createInboxSelection', () => {
it('shows a stack at one of its notifications until another is chosen', () => {
createRoot((dispose) => {
- const selection = createInboxSelection(() => [stack('a', ['1', '2'])]);
+ const selection = createInboxSelection(
+ () => [stack('a', ['1', '2'])],
+ memoryLocation().location
+ );
selection.select(stack('a', ['1', '2']), '2');
expect(selection.selectedNotification()?.id).toBe('2');
@@ -54,7 +75,7 @@ describe('createInboxSelection', () => {
it('opens where the row does once the chosen notification leaves the row', () => {
createRoot((dispose) => {
const [rows, setRows] = createSignal([stack('a', ['1', '2'])]);
- const selection = createInboxSelection(rows);
+ const selection = createInboxSelection(rows, memoryLocation().location);
selection.select(stack('a', ['1', '2']), '1');
setRows([stack('a', ['3', '2'])]);
@@ -67,7 +88,7 @@ describe('createInboxSelection', () => {
it('follows the shown row and keeps it once it leaves the list', () => {
createRoot((dispose) => {
const [rows, setRows] = createSignal([row('a'), row('b')]);
- const selection = createInboxSelection(rows);
+ const selection = createInboxSelection(rows, memoryLocation().location);
selection.select(row('a'));
setRows([row('a', 'r2'), row('b')]);
@@ -81,7 +102,10 @@ describe('createInboxSelection', () => {
it('re-aims when the shown row is chosen again', () => {
createRoot((dispose) => {
- const selection = createInboxSelection(() => [row('a')]);
+ const selection = createInboxSelection(
+ () => [row('a')],
+ memoryLocation().location
+ );
selection.select(row('a'));
expect(selection.navigationRequest()).toBe(0);
selection.select(row('a'));
@@ -93,7 +117,7 @@ describe('createInboxSelection', () => {
it('moves to the next row that stays when the shown row leaves', () => {
createRoot((dispose) => {
const rows = () => [row('a'), row('b'), row('c'), row('d')];
- const selection = createInboxSelection(rows);
+ const selection = createInboxSelection(rows, memoryLocation().location);
selection.select(row('b'));
expect(selection.afterLeaving(['c'])).toBe('stay');
@@ -105,4 +129,41 @@ describe('createInboxSelection', () => {
dispose();
});
});
+
+ it('adds a history entry for each row shown, unless told to replace', () => {
+ createRoot((dispose) => {
+ const { location, writes } = memoryLocation();
+ const selection = createInboxSelection(
+ () => [stack('a', ['1', '2']), row('b')],
+ location
+ );
+
+ selection.select(stack('a', ['1', '2']), '2');
+ selection.select(row('b'), undefined, { replace: true });
+ selection.select(row('b'));
+ selection.clear();
+
+ expect(writes).toEqual([
+ { next: { row: 'a', item: '2' }, replace: false },
+ { next: { row: 'b', item: '' }, replace: true },
+ { next: { row: '', item: '' }, replace: false },
+ ]);
+ expect(selection.selected()).toBeUndefined();
+ dispose();
+ });
+ });
+
+ it('shows the row the location names once the list loads it', () => {
+ createRoot((dispose) => {
+ const [rows, setRows] = createSignal<NotificationInboxRow[]>([]);
+ const { location } = memoryLocation({ row: 'b', item: '2' });
+ const selection = createInboxSelection(rows, location);
+ expect(selection.selected()).toBeUndefined();
+
+ setRows([row('a'), stack('b', ['1', '2'])]);
+ expect(selection.selected()?.id).toBe('b');
+ expect(selection.selectedNotification()?.id).toBe('2');
+ dispose();
+ });
+ });
});
diff --git a/apps/web/src/features/notifications-inbox/primitives/inbox-selection.ts b/apps/web/src/features/notifications-inbox/primitives/inbox-selection.ts
index e6cc44e83a..e70be3f71f 100644
--- a/apps/web/src/features/notifications-inbox/primitives/inbox-selection.ts
+++ b/apps/web/src/features/notifications-inbox/primitives/inbox-selection.ts
@@ -1,31 +1,44 @@
-import { type Accessor, batch, createSignal } from 'solid-js';
+import { type Accessor, createMemo, createSignal } from 'solid-js';
import type { NotificationInboxRow } from '../context/notifications-inbox-context';
+/** The shown row and the chosen notification of its stack; '' for none. */
+export type InboxShownRow = { row: string; item: string };
+
+/** Where the shown row is kept, such as the view's URL. */
+export type InboxShownRowLocation = {
+ shown: Accessor<InboxShownRow>;
+ /** `replace` overwrites the current history entry instead of adding one. */
+ show: (next: InboxShownRow, options: { replace: boolean }) => void;
+};
+
+type ShowOptions = { replace?: boolean };
+
/**
* The row shown in the preview, and which of its notifications when one was
- * chosen from its stack. It follows the row's latest version while the list
- * holds it, and keeps its last version once it leaves, so the preview doesn't
- * vanish under the reader.
+ * chosen from its stack, as `location` holds them. It follows the row's latest
+ * version while the list holds it, and keeps its last version once it leaves,
+ * so the preview doesn't vanish under the reader.
*/
export function createInboxSelection(
- rows: Accessor<readonly NotificationInboxRow[]>
+ rows: Accessor<readonly NotificationInboxRow[]>,
+ location: InboxShownRowLocation
) {
- const [snapshot, setSnapshot] = createSignal<NotificationInboxRow>();
- const [notificationId, setNotificationId] = createSignal<string>();
const [request, setRequest] = createSignal(0);
- const selected = () => {
- const current = snapshot();
- if (!current) return undefined;
- return rows().find((row) => row.id === current.id) ?? current;
- };
+ const selected = createMemo<NotificationInboxRow | undefined>((previous) => {
+ const id = location.shown().row;
+ if (!id) return undefined;
+ const current = rows().find((row) => row.id === id);
+ if (current) return current;
+ return previous?.id === id ? previous : undefined;
+ });
/**
* The chosen notification of the shown row, while the row still holds it.
* Without one the preview opens where the row does.
*/
const selectedNotification = () => {
- const id = notificationId();
+ const id = location.shown().item;
if (!id) return undefined;
return selected()?.content.notifications.find(
(notification) => notification.id === id
@@ -36,21 +49,22 @@ export function createInboxSelection(
* Show `row`, at one of its notifications when one is named; choosing what's
* shown again re-aims it at its location.
*/
- const select = (row: NotificationInboxRow, notification?: string) => {
- batch(() => {
- if (snapshot()?.id === row.id && notificationId() === notification) {
- setRequest((count) => count + 1);
- }
- setSnapshot(row);
- setNotificationId(notification);
- });
+ const select = (
+ row: NotificationInboxRow,
+ notification?: string,
+ options: ShowOptions = {}
+ ) => {
+ const next = { row: row.id, item: notification ?? '' };
+ const shown = location.shown();
+ if (shown.row === next.row && shown.item === next.item) {
+ setRequest((count) => count + 1);
+ return;
+ }
+ location.show(next, { replace: options.replace ?? false });
};
- const clear = () =>
- batch(() => {
- setSnapshot(undefined);
- setNotificationId(undefined);
- });
+ const clear = (options: ShowOptions = {}) =>
+ location.show({ row: '', item: '' }, { replace: options.replace ?? false });
/**
* Where to go when `leaving` rows leave the list while one of them is
@@ -60,7 +74,7 @@ export function createInboxSelection(
const afterLeaving = (
leaving: readonly string[]
): NotificationInboxRow | 'stay' | 'none' => {
- const current = snapshot();
+ const current = selected();
if (!current || !leaving.includes(current.id)) return 'stay';
const list = rows();
const index = list.findIndex((row) => row.id === current.id);
diff --git a/apps/web/src/features/notifications-inbox/views/notifications-calendar-pane.tsx b/apps/web/src/features/notifications-inbox/views/notifications-calendar-pane.tsx
index 88116ab09e..0c33ae41c8 100644
--- a/apps/web/src/features/notifications-inbox/views/notifications-calendar-pane.tsx
+++ b/apps/web/src/features/notifications-inbox/views/notifications-calendar-pane.tsx
@@ -5,8 +5,6 @@ import { PreviewFrame } from '@components/app/PreviewPanel';
import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import { lazyNamed } from '@core/util/lazyNamed';
-import { Show } from 'solid-js';
-import { NotificationsBreadcrumb } from '../components/notifications-breadcrumb';
import { useNotificationsCalendarPane } from '../context/notifications-calendar-context';
// The calendar grid (FullCalendar) only loads once a calendar notification opens.
@@ -28,18 +26,12 @@ export function NotificationsCalendarPane() {
<div class="flex size-full min-h-0">
<PreviewFrame
splitPanelContext={panel}
- headerLeading={<NotificationsBreadcrumb onReturn={calendar.onReturn} />}
hideHeader={!isTouchDevice()}
locationKey={() => `${search.eventId}:${search.occurrenceKey}`}
>
<CalendarView
route={notificationsCalendarRoute}
refocus={calendar.refocus}
- headerLeading={
- <Show when={!isTouchDevice()}>
- <NotificationsBreadcrumb onReturn={calendar.onReturn} />
- </Show>
- }
/>
</PreviewFrame>
</div>
diff --git a/apps/web/src/features/notifications-inbox/views/notifications-view.tsx b/apps/web/src/features/notifications-inbox/views/notifications-view.tsx
index ad1fb876ee..062834e3a0 100644
--- a/apps/web/src/features/notifications-inbox/views/notifications-view.tsx
+++ b/apps/web/src/features/notifications-inbox/views/notifications-view.tsx
@@ -72,7 +72,6 @@ import {
} from '../components/inbox-status-tabs';
import { NotificationRow } from '../components/notification-row';
import { NotificationStackItem } from '../components/notification-stack-item';
-import { NotificationsBreadcrumb } from '../components/notifications-breadcrumb';
import { RowActionButtons } from '../components/row-action-buttons';
import { NotificationsCalendarPaneProvider } from '../context/notifications-calendar-context';
import {
@@ -97,7 +96,11 @@ import {
} from '../primitives/inbox-date-headers';
import { createInboxFilters } from '../primitives/inbox-filters';
import { createInboxList } from '../primitives/inbox-list';
-import { createInboxSelection } from '../primitives/inbox-selection';
+import {
+ createInboxSelection,
+ type InboxShownRow,
+ type InboxShownRowLocation,
+} from '../primitives/inbox-selection';
import {
agentTurnParams,
crmCommentParams,
@@ -105,6 +108,8 @@ import {
import { createRowActions, rowButtons } from '../primitives/row-actions';
type ActivationMetadata = { event?: MouseEvent; newSplit?: boolean };
+/** Stepping through the list and moving on from a done row replace the entry. */
+type HistoryOptions = { replace?: boolean };
export type NotificationsViewProps = {
/** Open what a row is about, or one of its notifications; the host decides where. */
@@ -114,12 +119,19 @@ export type NotificationsViewProps = {
) => void;
/** Open the settings that decide which notifications are delivered. */
onOpenSettings: () => void;
+ /** Where the shown row is kept, so opening one is a history entry. */
+ shownRow: InboxShownRowLocation;
/** Calendar events show in the content area through the view's calendar route. */
calendarPreview: {
- /** Show the event in the content area; false when it can't be shown there. */
- open: (entity: CalendarPreviewSelection) => boolean;
- /** Leave the calendar, when it is shown. */
- close: () => void;
+ /**
+ * Show the event in the content area, keeping the row that chose it in
+ * the same history entry; false when it can't be shown there.
+ */
+ open: (
+ entity: CalendarPreviewSelection,
+ navigation: { shown: InboxShownRow; replace: boolean }
+ ) => boolean;
+ isOpen: Accessor<boolean>;
/** Bumped when the shown event is chosen again. */
refocus: Accessor<number>;
};
@@ -319,7 +331,7 @@ export function NotificationsView(props: NotificationsViewProps) {
const orchestrator = useGlobalBlockOrchestrator();
const guard = createPreviewSelectionGuard();
- const selection = createInboxSelection(rows);
+ const selection = createInboxSelection(rows, props.shownRow);
const previewTarget = createMemo(() => {
const row = selection.selected();
if (!row) return undefined;
@@ -335,19 +347,22 @@ export function NotificationsView(props: NotificationsViewProps) {
/**
* Show a row in the preview, at one of its notifications when one is named:
* a calendar event in the Calendar, anything else in its block. A row with
- * no inline preview opens instead.
+ * no inline preview opens instead. Each shown row is a history entry.
*/
const preview = (
row: NotificationInboxRow,
- notification?: UnifiedNotification
+ notification?: UnifiedNotification,
+ history: HistoryOptions = {}
) => {
const calendarEvent = calendarSelection(entityOf(row, notification));
if (
calendarEvent &&
guard.canSelect(undefined) &&
- props.calendarPreview.open(calendarEvent)
+ props.calendarPreview.open(calendarEvent, {
+ shown: { row: row.id, item: notification?.id ?? '' },
+ replace: history.replace ?? false,
+ })
) {
- selection.select(row, notification?.id);
guard(undefined);
markSeen(row);
return;
@@ -358,18 +373,39 @@ export function NotificationsView(props: NotificationsViewProps) {
return;
}
if (!guard.canSelect(target)) return;
- props.calendarPreview.close();
- selection.select(row, notification?.id);
+ selection.select(row, notification?.id, history);
guard(target);
markSeen(row);
};
- /** Leave what the content area shows for the empty state. */
- const closePreview = () => {
- props.calendarPreview.close();
- selection.clear();
- };
- const previewAfterMove = debounce(preview, 150);
+ // Back and forward change the shown row too; the preview claims what it
+ // shows, and yields to another split that already shows it. Touch has no
+ // preview to claim for.
+ createEffect(
+ on(
+ previewTarget,
+ (target, previous) => {
+ if (isTouchDevice()) return;
+ if (
+ target?.blockType === previous?.blockType &&
+ target?.blockId === previous?.blockId
+ ) {
+ return;
+ }
+ if (!guard(target)) selection.clear({ replace: true });
+ },
+ { defer: true }
+ )
+ );
+
+ /** Leave what the content area shows for the list. */
+ const closePreview = (history: HistoryOptions = {}) =>
+ selection.clear(history);
+ const previewAfterMove = debounce(
+ (row: NotificationInboxRow, notification?: UnifiedNotification) =>
+ preview(row, notification, { replace: true }),
+ 150
+ );
onCleanup(() => previewAfterMove.clear());
const list = createListController<InboxListItem, ActivationMetadata>({
@@ -407,8 +443,8 @@ export function NotificationsView(props: NotificationsViewProps) {
complete: (row) => {
stacks.collapse(row.id);
const next = selection.afterLeaving([row.id]);
- if (next === 'none') closePreview();
- else if (next !== 'stay') preview(next);
+ if (next === 'none') closePreview({ replace: true });
+ else if (next !== 'stay') preview(next, undefined, { replace: true });
return feed.markDone([row]);
},
notices: {
@@ -420,8 +456,8 @@ export function NotificationsView(props: NotificationsViewProps) {
const markDone = (done: readonly NotificationInboxRow[]) => {
for (const row of done) stacks.collapse(row.id);
const next = selection.afterLeaving(done.map((row) => row.id));
- if (next === 'none') closePreview();
- else if (next !== 'stay') preview(next);
+ if (next === 'none') closePreview({ replace: true });
+ else if (next !== 'stay') preview(next, undefined, { replace: true });
fireAndForget(inbox.markDone(done), 'notifications-inbox');
};
@@ -872,6 +908,13 @@ export function NotificationsView(props: NotificationsViewProps) {
asidePreferenceKey="notifications"
// Rows read as sentences, so the list starts wider than a nav rail.
aside={{ width: 360, max: 480, preserveDuringResize: false }}
+ // Narrow, the list and what it opens take turns.
+ asideList={{
+ open:
+ props.calendarPreview.isOpen() ||
+ previewTarget() !== undefined,
+ onBack: () => closePreview(),
+ }}
main={{ preferredWidth: 640 }}
resizable
>
@@ -916,10 +959,7 @@ export function NotificationsView(props: NotificationsViewProps) {
</ViewShell.Aside>
<ViewShell.Main class="overflow-hidden">
<NotificationsCalendarPaneProvider
- value={{
- refocus: props.calendarPreview.refocus,
- onReturn: closePreview,
- }}
+ value={{ refocus: props.calendarPreview.refocus }}
>
{/* A calendar event shows under the view's calendar route,
which loads lazily: suspend only this pane, so the list
@@ -945,11 +985,6 @@ export function NotificationsView(props: NotificationsViewProps) {
navigationRequest={selection.navigationRequest()}
orchestrator={orchestrator}
splitPanelContext={panel}
- headerLeading={
- <NotificationsBreadcrumb
- onReturn={closePreview}
- />
- }
/>
</Show>
)}
diff --git a/apps/web/src/lib/i18n/locales/en/common.ts b/apps/web/src/lib/i18n/locales/en/common.ts
index 690b1f9dcf..d6620183a9 100644
--- a/apps/web/src/lib/i18n/locales/en/common.ts
+++ b/apps/web/src/lib/i18n/locales/en/common.ts
@@ -1,5 +1,6 @@
export default {
add: 'Add',
+ back: 'Back',
addProperty: 'Add property',
addTags: 'Add tags',
emptyCollection: 'No items added yet',
diff --git a/apps/web/src/lib/i18n/locales/en/notifications-inbox.ts b/apps/web/src/lib/i18n/locales/en/notifications-inbox.ts
index 649d86622f..ad98acb728 100644
--- a/apps/web/src/lib/i18n/locales/en/notifications-inbox.ts
+++ b/apps/web/src/lib/i18n/locales/en/notifications-inbox.ts
@@ -55,7 +55,6 @@ export default {
undoFailed: 'Failed to undo',
// List states
- location: 'Notifications location',
loading: 'Loading notifications',
loadFailed: 'Notifications couldn’t be loaded.',
tryAgain: 'Try again',
diff --git a/docs/agent-guide/channels.md b/docs/agent-guide/channels.md
index 08df74becf..971b12519a 100644
--- a/docs/agent-guide/channels.md
+++ b/docs/agent-guide/channels.md
@@ -1042,11 +1042,12 @@ Chat remembers this choice independently of other workspaces and restores it
after reload. While no conversation is selected, the rail stays open regardless
of that choice and offers no **Hide navigation** control (`Cmd+.` is inert);
selecting a conversation applies the saved choice again. Chat uses
-the shared 256px default sidebar width and resize limits. In splits narrower than
-720px, navigation collapses; the hamburger or `Cmd+.` opens it as a slide-over
-with the same full sidebar contents. With no conversation selected, the
-slide-over opens on its own and closes once a conversation is picked; the
-backdrop or `Escape` still dismisses it. There is no separate skinny sidebar mode.
+the shared 256px default sidebar width and resize limits. In splits 720px wide or
+narrower, the rail and the conversation take turns at full width instead of a
+slide-over: with no conversation selected the rail fills the split (no Hide
+navigation, `Cmd+.` inert), and an open conversation shows **Back** (left arrow)
+where the hamburger was. Back opens the Channels list route, so browser or split
+back returns to the conversation. There is no separate skinny sidebar mode.
### Sidebar redesign rollout
@@ -1074,8 +1075,8 @@ collapses and sorts independently; open groups split the available height.
the channel filter, while the Conversations section lists channels and DMs with
threads the user participates in. Scrolling loads more. Selecting a conversation
filters the thread view instead of opening that conversation. On desktop, Threads
-pins navigation open with no Hide navigation control. In narrow splits, changing
-between Threads, All, and Recent preserves an already-open navigation overlay.
+pins navigation open with no Hide navigation control. In narrow splits the thread
+view fills the split like a conversation, and **Back** returns to All.
### Sectioned sidebar (flag on)
diff --git a/docs/agent-guide/navigation.md b/docs/agent-guide/navigation.md
index 2bd31df1fd..7e5c9703ff 100644
--- a/docs/agent-guide/navigation.md
+++ b/docs/agent-guide/navigation.md
@@ -449,7 +449,9 @@ saved wide-layout preference. Widening restores that preference, including in
Home and Chat: navigation returns unless explicitly hidden at desktop width.
Shrinking again starts with the overlay closed. Chat is the exception while no
conversation is selected: its navigation stays docked with no **Hide
-navigation** control, and narrow Chat opens the overlay on its own (see
+navigation** control. Views whose sidebar is their list (Chat, Notifications)
+skip the overlay when narrow: the list fills the split until something opens,
+which then fills it with **Back** in place of the hamburger (see
[Chat navigation rail](channels.md#chat-navigation-rail)).
Settings navigation always stays docked at desktop width with no **Hide
navigation** control; only its narrow overlay opens and closes.
diff --git a/docs/agent-guide/notifications.md b/docs/agent-guide/notifications.md
index e2ac58c820..d432497b9d 100644
--- a/docs/agent-guide/notifications.md
+++ b/docs/agent-guide/notifications.md
@@ -47,15 +47,20 @@ morning**, **Yesterday**, and so on), by each row's newest notification; `j`/`k`
skip them.
Click a row or press Enter to preview it beside the list, opened at the
-notification's message, thread, or comment, under a **Notifications >**
-breadcrumb that clears the preview. Previewing marks the row seen, including
+notification's message, thread, or comment. The shown row and stacked
+notification live in the URL (`sN.inbox.row`, `sN.inbox.item`), so each opened
+row is a history entry and browser or split back returns to the previous one;
+stepping with `j`/`k` and moving on from a done row replace the entry instead.
+In splits 720px wide or narrower the list fills the split until a row opens,
+which then fills it with **Back** (left arrow) returning to the list.
+Previewing marks the row seen, including
notifications the row hides, and drops its unread dot. With a preview open, `j`/`k` move it along the
list and through unfolded notifications; `l` or the right arrow unfolds the focused
stack and the left arrow folds it from anywhere inside it. Opening a notification
marks its whole row seen, and `e` on one marks its whole stack done. Choosing what's
shown again re-aims it. A calendar event or join request opens the Calendar
beside the list at the event, at `/app/notifications/calendar/<period>` with the
-event in `sN.calendar.*`, under the same breadcrumb; the list keeps its place.
+event in `sN.calendar.*`, with the row in the same entry; the list keeps its place.
Projects open in their own view instead. Shift-click or the alternate key opens a new
split. Hover a row and choose **Mark done**, or press `e`, to complete that row
only: the channel thread stays when the channel's top-level row is done, and an
diff --git a/docs/agent-guide/ui-conventions.md b/docs/agent-guide/ui-conventions.md
index b2cca922c2..d807aa980d 100644
--- a/docs/agent-guide/ui-conventions.md
+++ b/docs/agent-guide/ui-conventions.md
@@ -55,7 +55,10 @@ Main expands to its narrow layout. The sidebar remains inert through the closing
animation, then unmounts. Show navigation opens the dismissible overlay instead;
required navigation opens that overlay immediately. Returning to wide restores
the saved docked state without changing the sidebar preference. Reduced-motion
-settings and missing animation support skip the closing animation.
+settings and missing animation support skip the closing animation. A view whose
+aside is its entity list passes `asideList` instead: narrow, the list fills the
+shell until `open`, then Main does, with a Back button (calling `onBack`) in
+place of Show navigation. Chat and Notifications use it.
## Canonical desktop surfaces