Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions packages/ui/src/components/pages/Launcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@
* Launcher — iOS-like app/view launcher.
*
* Renders every available view as a names-only icon on swipeable pages. Tap
* launches; long-press enters edit mode where icons can be reordered (drag)
* and — for manageable (dynamic developer) views — edited or deleted. Page
* order is persisted via the pure `launcher-layout` model. Fully token-themed
* (light/dark + overrides) and renders no background of its own — the shared
* root `AppBackground` shows through, matching the home screen.
* launches; in the free-form (non-curated) mode a long-press enters edit mode
* where icons can be reordered (drag) and — for manageable (dynamic developer)
* views — edited or deleted, with the order persisted via the pure
* `launcher-layout` model. (The production mount via LauncherSurface always
* passes `pageGroups`, so it renders read-only curated pages; edit mode is
* exercised by the standalone stories / launcher-e2e.)
*
* The springboard renders no background of its own — the shared root
* `AppBackground` shows through, matching the home screen. Tiles, labels, the
* skeleton, and the pager chevrons deliberately use a FIXED white-on-wallpaper
* treatment (theme-independent, kept legible by a text-shadow/scrim over the
* ambient field) rather than light/dark theme tokens.
*/

import { Pencil, Trash2 } from "lucide-react";
Expand Down Expand Up @@ -288,15 +295,6 @@ export function Launcher({
setLayout((prev) => reconcileLayout(prev, availableIds));
}, [availableIds]);

// Keep the LOCAL active page index in range when pages shrink (views removed).
// When controlled, the store clamps the page, so this only guards the
// standalone path.
useEffect(() => {
if (pageControlled) return;
const pageCount = layout.pages.length > 0 ? layout.pages.length : 1;
setLocalPage((p) => (p > pageCount - 1 ? pageCount - 1 : p));
}, [layout.pages.length, pageControlled]);

const commit = useCallback((next: LauncherLayout) => {
setLayout(next);
writeLauncherLayout(next);
Expand Down Expand Up @@ -345,6 +343,16 @@ export function Launcher({
return filtered.length > 0 ? filtered : [[]];
}, [curatedPages, layout.pages]);

// Keep the LOCAL active page index in range when the RENDERED page count
// shrinks. Must clamp against `pages` (the actually-rendered list — curated in
// grouped mode, free-form otherwise), not `layout.pages`, which in grouped
// mode is a different, unrendered list. `pages` is always non-empty. When
// controlled, the store owns the clamp, so this only guards the standalone path.
useEffect(() => {
if (pageControlled) return;
setLocalPage((p) => Math.min(p, pages.length - 1));
}, [pages.length, pageControlled]);

// Report the page count up so an outer surface (the rail) can size the single
// unified page indicator. Fires only on an actual count change.
useEffect(() => {
Expand Down Expand Up @@ -435,11 +443,14 @@ export function Launcher({
onPointerUp={pager.handlers.onPointerUp}
onPointerCancel={pager.handlers.onPointerCancel}
onLostPointerCapture={pager.handlers.onLostPointerCapture}
// Swallow the click a committed inter-page swipe synthesizes so it
// can't tap-launch the tile that just slid under the finger.
onClickCapture={pager.handlers.onClickCapture}
>
<div
ref={pager.railRef}
data-testid="launcher-page-rail"
className="flex h-full min-h-0 w-full motion-reduce:transition-none"
className="flex h-full min-h-0 w-full"
>
{loading && entries.length === 0 ? (
<div className="flex h-full min-h-0 min-w-full items-start justify-center overflow-y-auto px-6 pt-2 pb-8">
Expand Down
24 changes: 24 additions & 0 deletions packages/ui/src/components/pages/launcher-curation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,30 @@ describe("curateLauncherPages", () => {
expect(ids(pages)).toEqual([["wallet", "automations"]]);
});

it("drops the alias path when an alias wins the tile, so launch/telemetry agree", () => {
// Only an aliased registration (todos → automations) is present, no canonical
// `automations`. The tile must carry the canonical id AND no alias path, so
// handleLaunch falls back to /apps/automations rather than /todos.
const pages = curateLauncherPages([entry("todos", { path: "/todos" })], {
isAosp: false,
enabledKinds: ENABLED,
cloudActive: true,
});
const tile = pages[0][0];
expect(tile.id).toBe("automations");
expect(tile.path).toBeUndefined();
});

it("keeps a non-aliased winner's real path intact", () => {
const pages = curateLauncherPages(
[entry("wallet", { path: "/wallet", kind: "view", state: "loaded" })],
{ isAosp: false, enabledKinds: ENABLED, cloudActive: true },
);
const tile = pages[0][0];
expect(tile.id).toBe("wallet");
expect(tile.path).toBe("/wallet");
});

it("appends other loaded apps after the curated order on page 1", () => {
const pages = curateLauncherPages(
[
Expand Down
11 changes: 10 additions & 1 deletion packages/ui/src/components/pages/launcher-curation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,16 @@ export function curateLauncherPages(
if (!existing || preferenceScore(entry) > preferenceScore(existing)) {
// Preserve the canonical id so navigation + telemetry stay stable even
// when an aliased registration (e.g. `wallet.inventory`) wins the tile.
byCanonical.set(canonicalId, { ...entry, id: canonicalId });
// When the id is REWRITTEN (an alias won), drop its alias `path` too, so
// handleLaunch falls back to `/apps/<canonicalId>` — the route the dedup
// presumes — instead of navigating to the alias route while recents +
// telemetry record the canonical id (a real launch/telemetry mismatch).
byCanonical.set(
canonicalId,
canonicalId === entry.id
? entry
: { ...entry, id: canonicalId, path: undefined },
);
}
}

Expand Down
30 changes: 11 additions & 19 deletions packages/ui/src/components/shell/HomeLauncherSurface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ export function HomeLauncherSurface({
setShellSurfacePage(initialPage);
}, [initialPage]);

// A committed flick must swallow the click that the browser synthesizes from
// the same press, so the flick doesn't also tap-launch the tile underneath.
const suppressClickRef = React.useRef(false);
// ONE pager owns the touch gesture per surface — the fix for the "two swipe
// actions stacked on top of each other" the user reported. The rail owns the
// gesture on the HOME half (swipe left → launcher) and while EDITING (the
Expand All @@ -65,27 +62,17 @@ export function HomeLauncherSurface({
page: page === "launcher" ? 1 : 0,
pageCount: 2,
enabled: railGestureEnabled,
// The hook arms + swallows the committed-swipe click itself (handlers.
// onClickCapture, attached on both halves below), so this stays a plain
// navigation intent — no local click-suppression bookkeeping.
onPageChange: (nextPage) => {
suppressClickRef.current = true;
window.setTimeout(() => {
suppressClickRef.current = false;
}, 0);
if (nextPage === 0) {
goHome();
} else {
goLauncher();
}
},
});
const suppressCommittedSwipeClick = React.useCallback(
(event: React.MouseEvent<HTMLDivElement>) => {
if (!suppressClickRef.current) return;
suppressClickRef.current = false;
event.preventDefault();
event.stopPropagation();
},
[],
);
// No page indicator: the dots collided with the floating chat composer, and
// the swipe gesture (left → launcher, right → home / back a page) is the
// sole, sufficient navigation. Paging across launcher pages stays a swipe.
Expand All @@ -106,11 +93,15 @@ export function HomeLauncherSurface({
<div
ref={pager.railRef}
data-testid="home-launcher-rail"
className="absolute inset-0 flex w-[200%] motion-reduce:transition-none"
className="absolute inset-0 flex w-[200%]"
>
<div
data-testid="home-launcher-home-page"
aria-hidden={page !== "home"}
// `inert` (not just aria-hidden) so the offscreen half is also removed
// from the tab order — a keyboard user can't focus a control hidden
// behind the visible page. Matches the Launcher's inert page pattern.
inert={page !== "home" || undefined}
// `touch-pan-y`: reserve vertical panning for the browser (the home
// widget list scrolls) but claim every horizontal gesture for the
// rail flick. Without it a touch device hands a horizontal drag to the
Expand All @@ -122,13 +113,14 @@ export function HomeLauncherSurface({
onPointerUp={pager.handlers.onPointerUp}
onPointerCancel={pager.handlers.onPointerCancel}
onLostPointerCapture={pager.handlers.onLostPointerCapture}
onClickCapture={suppressCommittedSwipeClick}
onClickCapture={pager.handlers.onClickCapture}
>
{home}
</div>
<div
data-testid="home-launcher-launcher-page"
aria-hidden={page !== "launcher"}
inert={page !== "launcher" || undefined}
// Same as the home half: vertical scroll (the tile grid) stays with
// the browser, horizontal flicks (right → back home) are ours.
className="relative h-full w-1/2 shrink-0 touch-pan-y"
Expand All @@ -137,7 +129,7 @@ export function HomeLauncherSurface({
onPointerUp={pager.handlers.onPointerUp}
onPointerCancel={pager.handlers.onPointerCancel}
onLostPointerCapture={pager.handlers.onLostPointerCapture}
onClickCapture={suppressCommittedSwipeClick}
onClickCapture={pager.handlers.onClickCapture}
>
{React.cloneElement(launcher, {
onNavigateHomeFromEdge: goHome,
Expand Down
104 changes: 99 additions & 5 deletions packages/ui/src/components/shell/NotificationCenter.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// @vitest-environment jsdom
import type { AgentNotification } from "@elizaos/core";
import { cleanup, render, screen, waitFor } from "@testing-library/react";
import {
cleanup,
render,
screen,
waitFor,
within,
} from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import {
Expand Down Expand Up @@ -152,12 +158,18 @@ describe("NotificationCenter", () => {
expect(screen.queryByText("Discord reply waiting")).not.toBeNull();
expect(screen.queryByText("Update installed")).not.toBeNull();

await user.click(screen.getByRole("tab", { name: "Reminders" }));
// Filter chips are toggle buttons (aria-pressed), scoped to the filter group.
const filterBar = screen.getByRole("group", {
name: "Filter notifications by category",
});
await user.click(
within(filterBar).getByRole("button", { name: "Reminders" }),
);
expect(screen.queryByText("Take medication")).not.toBeNull();
expect(screen.queryByText("Discord reply waiting")).toBeNull();
expect(screen.queryByText("Update installed")).toBeNull();

await user.click(screen.getByRole("tab", { name: "All" }));
await user.click(within(filterBar).getByRole("button", { name: "All" }));
expect(screen.queryByText("Take medication")).not.toBeNull();
expect(screen.queryByText("Discord reply waiting")).not.toBeNull();
expect(screen.queryByText("Update installed")).not.toBeNull();
Expand All @@ -173,7 +185,12 @@ describe("NotificationCenter", () => {
render(<NotificationCenter />);

await user.click(screen.getByRole("button", { name: /notifications/i }));
await user.click(screen.getByRole("tab", { name: "Reminders" }));
const filterBar = screen.getByRole("group", {
name: "Filter notifications by category",
});
await user.click(
within(filterBar).getByRole("button", { name: "Reminders" }),
);
expect(screen.queryByText("Update installed")).toBeNull();

await user.click(
Expand All @@ -184,8 +201,9 @@ describe("NotificationCenter", () => {
expect(screen.queryByText("Take medication")).toBeNull();
expect(screen.queryByText("Update installed")).not.toBeNull();
});
// The filter group collapses when only one category remains present.
expect(
screen.queryByRole("tablist", {
screen.queryByRole("group", {
name: "Filter notifications by category",
}),
).toBeNull();
Expand Down Expand Up @@ -372,4 +390,80 @@ describe("NotificationCenter", () => {
expect(screen.queryByTestId("notification-panel")).toBeNull();
expect(screen.getByText("Reminder due")).toBeTruthy();
});

it("controlled shells are accessible dialogs: aria-modal, focus moves in, focus returns on close", async () => {
seedNotifications([notification("f1", "Focus me", "system")]);
const Harness = ({ open }: { open: boolean }) => (
<>
<button type="button" data-testid="opener">
open
</button>
<NotificationCenter
variant="sheet"
open={open}
onOpenChange={() => {}}
/>
</>
);
// Start closed with the opener focused (the real flow: a trigger opens it).
const { rerender } = render(<Harness open={false} />);
(screen.getByTestId("opener") as HTMLElement).focus();
expect(document.activeElement).toBe(screen.getByTestId("opener"));

// Open: the effect captures the opener and moves focus into the dialog.
rerender(<Harness open />);
const dialog = screen.getByTestId("notification-sheet");
expect(dialog.getAttribute("aria-modal")).toBe("true");
await waitFor(() => expect(document.activeElement).toBe(dialog));

// Close: focus returns to the opener.
rerender(<Harness open={false} />);
await waitFor(() =>
expect(document.activeElement).toBe(screen.getByTestId("opener")),
);
});

it("empty state waits for hydration: shows Loading… before the inbox settles, then 'all caught up'", async () => {
const { __setHydratedForTests } = await import(
"../../state/notifications/notification-store"
);
// Keep the store's own hydrate() pending so `hydrated` stays false after mount.
mocks.listNotifications.mockReturnValue(new Promise(() => {}));

render(<NotificationCenter variant="sheet" open onOpenChange={() => {}} />);
// Not hydrated + no rows → neutral loading, NOT the definitive empty copy.
expect(screen.getByText("Loading…")).toBeTruthy();
expect(screen.queryByText("You're all caught up")).toBeNull();

// Hydration settles empty → the definitive empty state replaces Loading….
__setHydratedForTests(true);
await waitFor(() =>
expect(screen.getByText("You're all caught up")).toBeTruthy(),
);
expect(screen.queryByText("Loading…")).toBeNull();
});

it("category filter chips are toggle buttons (aria-pressed), not fake tabs", async () => {
seedNotifications([
notification("c1", "A reminder", "reminder"),
notification("c2", "A message", "message"),
]);
const user = userEvent.setup();
render(<NotificationCenter variant="sheet" open onOpenChange={() => {}} />);
await screen.findByText("A reminder");

// No ARIA tabs machinery (which would promise arrow-key nav we don't ship).
expect(screen.queryByRole("tablist")).toBeNull();
expect(screen.queryByRole("tab")).toBeNull();

const filterBar = screen.getByRole("group", {
name: "Filter notifications by category",
});
const remindersChip = within(filterBar).getByRole("button", {
name: "Reminders",
});
expect(remindersChip.getAttribute("aria-pressed")).toBe("false");
await user.click(remindersChip);
expect(remindersChip.getAttribute("aria-pressed")).toBe("true");
});
});
Loading
Loading