Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

feat(inbox): animate switching the Work panel's Inbox tabs (MUL-9926) (#11283)

Jiayuan Zhang8211a15cef56
diff --git a/e2e/inbox-section-header-locales.spec.ts b/e2e/inbox-section-header-locales.spec.ts
index 11d5dc089c..b0d7ef5639 100644
--- a/e2e/inbox-section-header-locales.spec.ts
+++ b/e2e/inbox-section-header-locales.spec.ts
@@ -86,12 +86,29 @@ test("Work panel Inbox header keeps every tab label whole and clear of its actio
await expect(tab(id)).toHaveAttribute("aria-selected", "true");
if (id === "snoozed") await expect(tab(id), `${locale}: snoozed count`).toContainText(String(SNOOZED));
- const found = await tab(id).evaluate((openTab) => {
+ const found = await tab(id).evaluate(async (openTab) => {
const tablist = openTab.closest<HTMLElement>('[role="tablist"]')!;
const header = tablist.closest("section")!.firstElementChild as HTMLElement;
+ // A switch slides the highlight and unfolds the new tab's name:
+ // measure once the tabs have held still for a few frames.
+ const frame = () => new Promise(requestAnimationFrame);
+ const layout = () =>
+ [...tablist.querySelectorAll("*")].map((el) => el.getBoundingClientRect().width).join();
+ for (let still = 0, last = "", n = 0; still < 5 && n < 120; n++) {
+ await frame();
+ const now = layout();
+ still = now === last ? still + 1 : 0;
+ last = now;
+ }
// Visually hidden copy (sr-only names, the open section's chevron)
- // is 1px wide by design and takes no part in the layout.
- const shown = (el: Element) => el.getBoundingClientRect().width > 1;
+ // is 1px wide by design and takes no part in the layout, and so is
+ // a closed tab's name, folded to nothing beside its icon.
+ const shown = (el: Element) => {
+ for (let node: Element | null = el; node && node !== tablist; node = node.parentElement) {
+ if (node.getBoundingClientRect().width <= 1) return false;
+ }
+ return true;
+ };
const name = (el: Element) =>
el.getAttribute("aria-label") || el.getAttribute("data-inbox-tab") || el.textContent?.trim();
const tabs = [...tablist.querySelectorAll<HTMLElement>("[data-inbox-tab]")];
diff --git a/packages/views/inbox/components/inbox-tabs.tsx b/packages/views/inbox/components/inbox-tabs.tsx
index fa6b49d54d..1160906e88 100644
--- a/packages/views/inbox/components/inbox-tabs.tsx
+++ b/packages/views/inbox/components/inbox-tabs.tsx
@@ -1,8 +1,11 @@
"use client";
-import type { KeyboardEvent } from "react";
+import { useLayoutEffect, useRef, useState, type KeyboardEvent, type RefObject } from "react";
+import { animate, motion, useMotionValue, type AnimationPlaybackControls, type MotionValue } from "motion/react";
+import { useReducedMotion } from "@multica/core/appearance";
import { AlarmClock, Archive, Inbox } from "@multica/ui/icons";
import { Tooltip, TooltipContent, TooltipTrigger } from "@multica/ui/components/ui/tooltip";
+import { UI_EASE_OUT, UI_MOTION_DURATION } from "@multica/ui/lib/motion";
import { cn } from "@multica/ui/lib/utils";
import { useT } from "../../i18n";
import type { InboxTab } from "./inbox-view";
@@ -23,7 +26,9 @@ const TAB_ICONS: Record<InboxTab, typeof Inbox> = {
* In the section header only the open tab carries its name: the other two are
* icons named by a tooltip, so at the panel's default width no label is cut
* down to its first letter. The unread count stays on the Inbox
- * icon; the snoozed count moves into its tooltip.
+ * icon; the snoozed count moves into its tooltip. On a switch the highlight
+ * slides to the new tab while its name unfolds and the old one folds back
+ * into its icon, so the name visibly moves where it went.
*/
export function InboxTabs({
tab,
@@ -46,6 +51,13 @@ export function InboxTabs({
className?: string;
}) {
const { t } = useT("inbox");
+ const reduceMotion = useReducedMotion();
+ const listRef = useRef<HTMLDivElement>(null);
+ const section = size === "section";
+ // The tab folding back into its icon keeps shrinking with the others until
+ // it has folded, rather than holding its place against the open one.
+ const [folding, setFolding] = useState<InboxTab | null>(null);
+ const highlight = useTabSwitchMotion(listRef, tab, section, reduceMotion ? 0 : UI_MOTION_DURATION.standard, setFolding);
const labels: Record<InboxTab, string> = {
inbox: t(($) => $.page.title),
snoozed: t(($) => $.list.snoozed_title),
@@ -64,11 +76,19 @@ export function InboxTabs({
return (
<div
+ ref={listRef}
role="tablist"
aria-label={labels.inbox}
onKeyDown={onKeyDown}
- className={cn("flex min-w-0 items-center gap-0.5", size === "section" ? "-ml-1.5" : "-ml-2", className)}
+ className={cn("relative flex min-w-0 items-center gap-0.5", section ? "-ml-1.5" : "-ml-2", className)}
>
+ {section && (
+ <motion.span
+ aria-hidden
+ className="absolute top-0 left-0 h-5 rounded-md bg-surface-selected"
+ style={{ x: highlight.x, width: highlight.width }}
+ />
+ )}
{TABS.map((id) => {
const active = id === tab;
const count = counts[id] ?? 0;
@@ -85,19 +105,27 @@ export function InboxTabs({
tabIndex={active ? 0 : -1}
onClick={() => onSelect(id)}
className={cn(
- "flex items-center gap-1 rounded-md outline-none transition-colors focus-visible:outline-2 focus-visible:outline-ring",
- size === "section" ? "h-5" : "h-7 px-2",
+ "flex items-center rounded-md outline-none transition-colors focus-visible:outline-2 focus-visible:outline-ring",
+ section ? "relative h-5 px-1" : "h-7 gap-1 px-2",
// The open tab gives up width before the icons do; a label
// still too long for the panel (Spanish, French) truncates.
- iconOnly ? "shrink-0 px-1" : size === "section" ? "min-w-0 px-1.5" : "min-w-0",
- active ? "bg-surface-selected text-foreground" : "text-muted-foreground hover:text-foreground",
+ active || id === folding ? "min-w-0" : "shrink-0",
+ active ? "text-foreground" : "text-muted-foreground hover:text-foreground",
+ active && !section && "bg-surface-selected",
)}
>
- {iconOnly ? (
+ {section ? (
+ // A closed tab's name is folded to nothing rather than hidden,
+ // so it still names the tab; a switch animates both parts.
<>
- <Icon aria-hidden className="size-3.5" />
- <span className="sr-only">{labels[id]}</span>
- {count > 0 && <span className={cn(countClass, id !== "inbox" && "sr-only")}>{count}</span>}
+ <span data-tab-icon aria-hidden className={cn("flex shrink-0 items-center overflow-hidden", active && "w-0 opacity-0")}>
+ <Icon className="size-3.5 shrink-0" />
+ </span>
+ <span data-tab-label className={cn("flex min-w-0 items-center overflow-hidden", !active && "w-0 opacity-0")}>
+ <span className="truncate px-0.5">{labels[id]}</span>
+ {id !== "inbox" && count > 0 && <span className={cn(countClass, "ml-0.5 pr-0.5")}>{count}</span>}
+ </span>
+ {id === "inbox" && count > 0 && <span className={cn(countClass, active ? "px-0.5" : "ml-1")}>{count}</span>}
</>
) : (
<>
@@ -119,3 +147,134 @@ export function InboxTabs({
</div>
);
}
+
+const EASE = { ease: UI_EASE_OUT } as const;
+
+/**
+ * Animates a switch between the section's tabs: the highlight slides to the
+ * new tab while its name unfolds and the old tab's folds back into its icon.
+ *
+ * Everything is measured once, before the first frame paints: where each part
+ * is now and where the switch leaves it, header space the switch frees or
+ * takes included. Every part then eases there on the same curve, the
+ * highlight with them, from where it is to the new tab's final box.
+ */
+function useTabSwitchMotion(
+ listRef: RefObject<HTMLDivElement | null>,
+ tab: InboxTab,
+ enabled: boolean,
+ seconds: number,
+ setFolding: (tab: InboxTab | null) => void,
+): { x: MotionValue<number>; width: MotionValue<number> } {
+ const x = useMotionValue(0);
+ const width = useMotionValue(0);
+ const shown = useRef<InboxTab | null>(null);
+ // The open tab's name as it last settled: where it folds from.
+ const openLabelWidth = useRef(0);
+ const running = useRef<AnimationPlaybackControls[]>([]);
+
+ useLayoutEffect(() => {
+ const list = listRef.current;
+ if (!list) return;
+ const button = (id: InboxTab) => list.querySelector<HTMLElement>(`[data-inbox-tab="${id}"]`)!;
+ const part = (id: InboxTab, name: "icon" | "label") => button(id).querySelector<HTMLElement>(`[data-tab-${name}]`)!;
+ if (!enabled) {
+ // Motion turned off mid-switch: drop what the stopped animation left.
+ shown.current = null;
+ for (const el of list.querySelectorAll<HTMLElement>("[data-tab-icon], [data-tab-label]")) {
+ el.style.width = "";
+ el.style.opacity = "";
+ el.querySelector<HTMLElement>(".truncate")?.style.removeProperty("text-overflow");
+ }
+ return;
+ }
+ const parts = TABS.flatMap((id) => [part(id, "icon"), part(id, "label")]);
+ const box = (el: HTMLElement) => {
+ const rect = el.getBoundingClientRect();
+ return { x: rect.left - list.getBoundingClientRect().left, w: rect.width };
+ };
+ const settle = () => {
+ for (const el of parts) {
+ el.style.width = "";
+ el.style.opacity = "";
+ el.querySelector<HTMLElement>(".truncate")?.style.removeProperty("text-overflow");
+ }
+ const target = box(button(tab));
+ x.set(target.x);
+ width.set(target.w);
+ openLabelWidth.current = part(tab, "label").getBoundingClientRect().width;
+ };
+
+ const from = shown.current;
+ shown.current = tab;
+
+ let cancelled = false;
+ if (from !== null && from !== tab && seconds > 0) {
+ // Where every part is: mid-switch, its inline style; settled, what the
+ // tab it belongs to showed before this switch.
+ const start = parts.map((el) => {
+ if (el.style.width) return { w: parseFloat(el.style.width), o: parseFloat(el.style.opacity || "1") };
+ const id = el.closest<HTMLElement>("[data-inbox-tab]")!.dataset.inboxTab as InboxTab;
+ if (el.hasAttribute("data-tab-label")) return id === from ? { w: openLabelWidth.current, o: 1 } : { w: 0, o: 0 };
+ return id === from ? { w: 0, o: 0 } : { w: el.firstElementChild!.getBoundingClientRect().width, o: 1 };
+ });
+ const highlightFrom = { x: x.get(), w: width.get() };
+
+ // Where the switch leaves them, the old tab already holding its place
+ // as it will once folded.
+ for (const el of parts) {
+ el.style.width = "";
+ el.style.opacity = "";
+ }
+ button(from).style.flexShrink = "0";
+ const end = parts.map((el) => ({ w: el.getBoundingClientRect().width, o: el.classList.contains("opacity-0") ? 0 : 1 }));
+ const toEnd = box(button(tab));
+ button(from).style.flexShrink = "";
+
+ parts.forEach((el, i) => {
+ el.style.width = `${start[i]!.w}px`;
+ el.style.opacity = String(start[i]!.o);
+ el.querySelector<HTMLElement>(".truncate")?.style.setProperty("text-overflow", "clip");
+ });
+
+ const transition = { duration: seconds, ...EASE };
+ running.current = [
+ ...parts.map((el, i) =>
+ animate(el, { width: [`${start[i]!.w}px`, `${end[i]!.w}px`], opacity: [start[i]!.o, end[i]!.o] }, transition),
+ ),
+ // Straight to where the new tab ends up, on the parts' curve. Tracking
+ // the tabs as they move would bulge past the end when the new tab
+ // starts far from where it settles.
+ animate(x, [highlightFrom.x, toEnd.x], transition),
+ animate(width, [highlightFrom.w, toEnd.w], transition),
+ ];
+ setFolding(from);
+ void Promise.all(running.current).then(() => {
+ if (cancelled) return;
+ running.current = [];
+ setFolding(null);
+ settle();
+ });
+ } else {
+ setFolding(null);
+ settle();
+ }
+
+ // A count arriving, the panel resizing or showing from hidden moves the
+ // tabs without a switch.
+ const observer = new ResizeObserver(() => {
+ if (running.current.length === 0) settle();
+ });
+ TABS.forEach((id) => observer.observe(button(id)));
+ parts.forEach((el) => observer.observe(el));
+ return () => {
+ cancelled = true;
+ observer.disconnect();
+ // Stopped where they are: a switch mid-way starts from these inline styles.
+ for (const controls of running.current) controls.stop();
+ running.current = [];
+ };
+ }, [listRef, tab, enabled, seconds, setFolding, x, width]);
+
+ return { x, width };
+}
diff --git a/packages/views/layout/panels/inbox-section.test.tsx b/packages/views/layout/panels/inbox-section.test.tsx
index 0ff6ac6eba..adad0802dd 100644
--- a/packages/views/layout/panels/inbox-section.test.tsx
+++ b/packages/views/layout/panels/inbox-section.test.tsx
@@ -3,6 +3,7 @@ import { act, fireEvent, screen, waitFor, within } from "@testing-library/react"
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { ApiError } from "@multica/core/api";
+import { useAppearanceStore } from "@multica/core/appearance";
import { createQueryClient } from "@multica/core/query-client";
import {
DEFAULT_SIDEBAR_INBOX_SETTINGS,
@@ -490,8 +491,10 @@ describe("InboxSection", () => {
it("names only the open tab on screen, and keeps focus on the tab the arrow keys move to", () => {
renderSection([item({ id: "n1", issue_id: "issue-a" })]);
const tablist = screen.getByRole("tablist");
- expect(within(tablist).getByText("Inbox")).not.toHaveClass("sr-only");
- expect(within(tablist).getByText("Snoozed")).toHaveClass("sr-only");
+ // A closed tab's name is folded away, still naming the tab for a screen reader.
+ const label = (name: string) => within(tablist).getByText(name).closest("[data-tab-label]");
+ expect(label("Inbox")).not.toHaveClass("opacity-0");
+ expect(label("Snoozed")).toHaveClass("w-0", "opacity-0");
const inbox = screen.getByRole("tab", { name: /^Inbox/ });
inbox.focus();
@@ -499,7 +502,8 @@ describe("InboxSection", () => {
const snoozed = screen.getByRole("tab", { name: /^Snoozed/ });
expect(snoozed).toHaveAttribute("aria-selected", "true");
expect(snoozed).toHaveFocus();
- expect(within(tablist).getByText("Snoozed")).not.toHaveClass("sr-only");
+ expect(label("Snoozed")).not.toHaveClass("opacity-0");
+ expect(label("Inbox")).toHaveClass("w-0", "opacity-0");
});
it("opens the display settings from their own button, as the other sections do", async () => {
@@ -652,8 +656,8 @@ describe("InboxSection", () => {
expect(tab).toHaveTextContent("1");
fireEvent.click(tab);
expect(tab).toHaveAttribute("aria-selected", "true");
+ expect(await screen.findByRole("link", { name: /^MUL-26/ })).toHaveAttribute("href", "/acme/inbox?view=snoozed&issue=issue-z");
expect(rows()).toHaveLength(0);
- expect(screen.getByRole("link", { name: /^MUL-26/ })).toHaveAttribute("href", "/acme/inbox?view=snoozed&issue=issue-z");
// The bulk actions act on the live Inbox and snoozed issues have no filter: no actions menu here.
expect(screen.queryByRole("button", { name: "Inbox actions" })).toBeNull();
@@ -661,6 +665,37 @@ describe("InboxSection", () => {
expect(state.unsnooze).toHaveBeenCalledWith(expect.objectContaining({ id: "z1" }));
});
+ it("swaps the lists at once with reduced motion", () => {
+ useAppearanceStore.getState().set({ reduceMotion: true });
+ renderSection([item({ id: "n1", issue_id: "issue-a" })], null, "/acme/issues", [], [
+ { issue_id: "issue-z", issue_identifier: "MUL-26", item_id: "z1", snoozed_until: "2099-01-01T09:00:00Z", snoozed_at: "2026-11-10T09:00:00Z", updates: 0 },
+ ]);
+ try {
+ fireEvent.click(screen.getByRole("tab", { name: /^Snoozed/ }));
+ expect(rows()).toHaveLength(0);
+ expect(screen.getByRole("link", { name: /^MUL-26/ })).toBeInTheDocument();
+ } finally {
+ useAppearanceStore.getState().reset();
+ }
+ });
+
+ it("lets go of the list's height when another tab opens while the archive is still loading", async () => {
+ apiMock.listArchivedInboxPage.mockReturnValue(new Promise(() => {}));
+ renderSection([item({ id: "n1", issue_id: "issue-a" })], null, "/acme/issues", [], [
+ { issue_id: "issue-z", issue_identifier: "MUL-26", item_id: "z1", snoozed_until: "2099-01-01T09:00:00Z", snoozed_at: "2026-11-10T09:00:00Z", updates: 0 },
+ ]);
+ const body = () => document.querySelector<HTMLElement>("[data-inbox-body]")!;
+
+ fireEvent.click(screen.getByRole("tab", { name: /^Archived/ }));
+ await waitFor(() => expect(rows()).toHaveLength(0));
+ expect(body()).toHaveClass("overflow-hidden");
+
+ fireEvent.click(screen.getByRole("tab", { name: /^Snoozed/ }));
+ expect(await screen.findByRole("link", { name: /^MUL-26/ })).toBeInTheDocument();
+ await waitFor(() => expect(body()).not.toHaveClass("overflow-hidden"));
+ expect(body().style.height).not.toMatch(/px$/);
+ });
+
it("lists the archive in a tab, each row opening there and restoring from its button", async () => {
apiMock.listArchivedInboxPage.mockResolvedValue({
items: [item({ id: "a1", issue_id: "issue-x", title: "Done with this", archived: true })],
diff --git a/packages/views/layout/panels/inbox-section.tsx b/packages/views/layout/panels/inbox-section.tsx
index 6c0fd60748..26d01dc1db 100644
--- a/packages/views/layout/panels/inbox-section.tsx
+++ b/packages/views/layout/panels/inbox-section.tsx
@@ -8,7 +8,7 @@ import { toast } from "sonner";
import { useReducedMotion } from "@multica/core/appearance";
import { AlarmClock, Archive, ArchiveRestore, BellOff, BookCheck, CheckCheck, Filter, ListChecks, MoreHorizontal } from "@multica/ui/icons";
import { IconButton } from "@multica/ui/components/common/icon-button";
-import { UI_EASE_OUT, UI_MOTION_DURATION } from "@multica/ui/lib/motion";
+import { UI_EASE_IN, UI_EASE_OUT, UI_MOTION_DURATION } from "@multica/ui/lib/motion";
import { cn } from "@multica/ui/lib/utils";
import { useIsCompact } from "@multica/ui/hooks/use-mobile";
import { TooltipHint } from "@multica/ui/components/common/tooltip-hint";
@@ -284,6 +284,14 @@ export function InboxSection({
/>
);
+ // Every tab shows rows or a note once it has loaded; until then it shows nothing.
+ const tabLoading =
+ tab === "inbox"
+ ? displayed.length === 0 && !list.filtered && list.load === "loading"
+ : tab === "snoozed"
+ ? snoozed.rows.length === 0 && snoozed.load === "loading"
+ : archived.items.length === 0 && !archived.query.isError && !archived.query.isSuccess;
+
return (
<PanelSection
label={t(($) => $.nav.inbox)}
@@ -333,87 +341,145 @@ export function InboxSection({
</div>
}
>
- {tab === "snoozed" ? (
- <SnoozedSectionList
- wsId={wsId}
- list={snoozed}
- limit={limit}
- openKey={pageTab === "snoozed" ? pageKey : null}
- />
- ) : tab === "archived" ? (
- <ArchivedSectionList
- archived={archived}
- limit={limit}
- openKey={pageTab === "archived" ? pageKey : null}
- />
- ) : displayed.length > 0 ? (
- displayed.length > VIRTUALIZE_AFTER && scrollRef ? (
- <VirtualInboxList items={displayed} compact={compact} renderRow={renderRow} />
- ) : (
- <PanelList data-sidebar-list={INBOX_LIST} className={compact ? undefined : "space-y-0.5"}>
- <AnimatePresence initial={false}>
- {displayed.map((item) => renderRow(item))}
- </AnimatePresence>
- </PanelList>
- )
- ) : list.load === "failed" ? (
- // A list that never loaded is not an empty Inbox: say so and offer
- // another try rather than "No notifications".
- <div role="alert" className={cn(PANEL_ROW_CLASS, "pl-[2.375rem] text-caption text-faint-foreground")}>
- <span className="min-w-0 flex-1 truncate">{tInbox(($) => $.errors.load_failed)}</span>
- <button
- type="button"
- disabled={list.retrying}
- className="shrink-0 rounded-md px-1 font-medium text-muted-foreground outline-none hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50"
- onClick={list.retry}
- >
- {tInbox(($) => $.list.retry)}
- </button>
- </div>
- ) : list.filtered ? (
- <div className={cn(PANEL_ROW_CLASS, "pl-[2.375rem] text-caption text-faint-foreground")}>
- <span className="min-w-0 flex-1 truncate">{tInbox(($) => $.filters.empty)}</span>
+ <InboxTabBody tab={tab} loading={tabLoading}>
+ {tab === "snoozed" ? (
+ <SnoozedSectionList
+ wsId={wsId}
+ list={snoozed}
+ limit={limit}
+ openKey={pageTab === "snoozed" ? pageKey : null}
+ />
+ ) : tab === "archived" ? (
+ <ArchivedSectionList
+ archived={archived}
+ limit={limit}
+ openKey={pageTab === "archived" ? pageKey : null}
+ />
+ ) : displayed.length > 0 ? (
+ displayed.length > VIRTUALIZE_AFTER && scrollRef ? (
+ <VirtualInboxList items={displayed} compact={compact} renderRow={renderRow} />
+ ) : (
+ <PanelList data-sidebar-list={INBOX_LIST} className={compact ? undefined : "space-y-0.5"}>
+ <AnimatePresence initial={false}>
+ {displayed.map((item) => renderRow(item))}
+ </AnimatePresence>
+ </PanelList>
+ )
+ ) : list.load === "failed" ? (
+ // A list that never loaded is not an empty Inbox: say so and offer
+ // another try rather than "No notifications".
+ <div role="alert" className={cn(PANEL_ROW_CLASS, "pl-[2.375rem] text-caption text-faint-foreground")}>
+ <span className="min-w-0 flex-1 truncate">{tInbox(($) => $.errors.load_failed)}</span>
+ <button
+ type="button"
+ disabled={list.retrying}
+ className="shrink-0 rounded-md px-1 font-medium text-muted-foreground outline-none hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring disabled:pointer-events-none disabled:opacity-50"
+ onClick={list.retry}
+ >
+ {tInbox(($) => $.list.retry)}
+ </button>
+ </div>
+ ) : list.filtered ? (
+ <div className={cn(PANEL_ROW_CLASS, "pl-[2.375rem] text-caption text-faint-foreground")}>
+ <span className="min-w-0 flex-1 truncate">{tInbox(($) => $.filters.empty)}</span>
+ <button
+ type="button"
+ className="shrink-0 rounded-md px-1 font-medium text-muted-foreground outline-none hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
+ onClick={() => clearFilters(wsId)}
+ >
+ {tInbox(($) => $.filters.clear)}
+ </button>
+ </div>
+ ) : list.load === "loaded" ? (
+ <p className={cn(PANEL_ROW_CLASS, "pl-[2.375rem] text-caption text-faint-foreground")}>
+ {t(($) => $.panels.work.inbox_empty)}
+ </p>
+ ) : null}
+ {tab === "inbox" && all.length > limit && (
<button
type="button"
- className="shrink-0 rounded-md px-1 font-medium text-muted-foreground outline-none hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
- onClick={() => clearFilters(wsId)}
+ aria-expanded={expanded}
+ className={cn(PANEL_ROW_CLASS, panelRowStateClass(false), "pl-[2.375rem] text-caption")}
+ onClick={() => setExpanded(!expanded)}
>
- {tInbox(($) => $.filters.clear)}
+ {expanded
+ ? t(($) => $.sidebar.show_fewer_pins)
+ : t(($) => $.sidebar.show_more_pins, { count: all.length - limit })}
</button>
- </div>
- ) : list.load === "loaded" ? (
- <p className={cn(PANEL_ROW_CLASS, "pl-[2.375rem] text-caption text-faint-foreground")}>
- {t(($) => $.panels.work.inbox_empty)}
- </p>
- ) : null}
- {tab === "inbox" && all.length > limit && (
- <button
- type="button"
- aria-expanded={expanded}
- className={cn(PANEL_ROW_CLASS, panelRowStateClass(false), "pl-[2.375rem] text-caption")}
- onClick={() => setExpanded(!expanded)}
- >
- {expanded
- ? t(($) => $.sidebar.show_fewer_pins)
- : t(($) => $.sidebar.show_more_pins, { count: all.length - limit })}
- </button>
- )}
- {/* The sidebar sits behind a drawer on a phone, so the full list keeps its page there. */}
- {isCompact && (
- <PanelList>
- <PanelLink
- href={inboxTabHref(p, tab)}
- icon={<span className="size-4" aria-hidden />}
- label={t(($) => $.panels.work.inbox_all)}
- active={onInboxPage && !pageKey && pageTab === tab}
- className="text-caption"
- />
- </PanelList>
- )}
+ )}
+ {/* The sidebar sits behind a drawer on a phone, so the full list keeps its page there. */}
+ {isCompact && (
+ <PanelList>
+ <PanelLink
+ href={inboxTabHref(p, tab)}
+ icon={<span className="size-4" aria-hidden />}
+ label={t(($) => $.panels.work.inbox_all)}
+ active={onInboxPage && !pageKey && pageTab === tab}
+ className="text-caption"
+ />
+ </PanelList>
+ )}
+ </InboxTabBody>
</PanelSection>
);
}
+/**
+ * The open tab's list. A switch fades the old rows out and the new ones in;
+ * while the next tab loads the list keeps the height it had, then eases to
+ * the new one, so the sections below it do not jump.
+ */
+function InboxTabBody({ tab, loading, children }: { tab: InboxTab; loading: boolean; children: ReactNode }) {
+ const reduceMotion = useReducedMotion();
+ const ref = useRef<HTMLDivElement>(null);
+ // The height the list keeps from the switch until the next tab's rows are in.
+ const [held, setHeld] = useState<number | null>(null);
+ // The tab whose rows are in. A tab's rows mount once the previous rows have
+ // faded out, or at once when none were in (that tab was still loading).
+ const [shown, setShown] = useState<InboxTab | null>(loading ? null : tab);
+ const switchedTo = useRef(tab);
+
+ useLayoutEffect(() => {
+ if (switchedTo.current === tab) return;
+ switchedTo.current = tab;
+ if (!ref.current) return;
+ // Measured before paint, while the old rows are still in.
+ setHeld(ref.current.offsetHeight);
+ }, [tab, reduceMotion]);
+
+ if (reduceMotion) return <>{children}</>;
+ const holding = held !== null && (shown !== tab || loading);
+ return (
+ <motion.div
+ ref={ref}
+ data-inbox-body
+ initial={false}
+ animate={{ height: holding ? held : "auto" }}
+ transition={{ duration: holding ? 0 : UI_MOTION_DURATION.standard, ease: UI_EASE_OUT }}
+ onAnimationComplete={() => {
+ if (!holding) setHeld(null);
+ }}
+ className={cn(held !== null && "overflow-hidden")}
+ >
+ <AnimatePresence mode="wait" initial={false}>
+ {!loading && (
+ <motion.div
+ key={tab}
+ ref={(node) => {
+ if (node) setShown(tab);
+ }}
+ initial={{ opacity: 0 }}
+ animate={{ opacity: 1, transition: { duration: UI_MOTION_DURATION.fast, ease: UI_EASE_OUT } }}
+ exit={{ opacity: 0, transition: { duration: UI_MOTION_DURATION.micro, ease: UI_EASE_IN } }}
+ >
+ {children}
+ </motion.div>
+ )}
+ </AnimatePresence>
+ </motion.div>
+ );
+}
+
/**
* Past this many rows (only reachable through "Show N more") the section
* mounts just the rows near the panel's viewport. Every mounted row