Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

feat(ui): one release notice, a scalable language switcher and a fuller not-found page (#3327)

Raghav Chamadiya3289287e2299
diff --git a/packages/ui/__tests__/dead-code/dead-code-view.test.tsx b/packages/ui/__tests__/dead-code/dead-code-view.test.tsx
index 2ab0491de..ba935337c 100644
--- a/packages/ui/__tests__/dead-code/dead-code-view.test.tsx
+++ b/packages/ui/__tests__/dead-code/dead-code-view.test.tsx
@@ -299,7 +299,8 @@ describe("DeadCodeView", () => {
).not.toBeInTheDocument(),
);
expect(screen.queryByText("No dead code found")).not.toBeInTheDocument();
- expect(screen.getByText("Every finding is resolved or set aside")).toBeInTheDocument();
+ // The row leaves and the resolved state arrives in separate renders.
+ expect(await screen.findByText("Every finding is resolved or set aside")).toBeInTheDocument();
const undo = lastUndoAction();
await undo.onClick();
diff --git a/packages/ui/__tests__/shared/release-notice.test.tsx b/packages/ui/__tests__/shared/release-notice.test.tsx
index b51d6869b..b459cc6b9 100644
--- a/packages/ui/__tests__/shared/release-notice.test.tsx
+++ b/packages/ui/__tests__/shared/release-notice.test.tsx
@@ -1,29 +1,59 @@
+import { describe, expect, it, vi, beforeEach } from "vitest";
import { fireEvent, render, screen } from "@testing-library/react";
-import { afterEach, describe, expect, it } from "vitest";
-
import { ReleaseNotice } from "../../src/shared/release-notice";
-afterEach(() => window.localStorage.clear());
-
describe("ReleaseNotice", () => {
- it("reads as one line with the explanation behind a toggle", async () => {
+ beforeEach(() => window.localStorage.clear());
+
+ it("renders title, body and action", () => {
+ render(
+ <ReleaseNotice id="a" version="1" title="Changed." action={<a href="/x">See what changed</a>}>
+ Body copy.
+ </ReleaseNotice>,
+ );
+ expect(screen.getByText("Changed.")).toBeInTheDocument();
+ expect(screen.getByText(/Body copy/)).toBeInTheDocument();
+ expect(screen.getByRole("link", { name: "See what changed" })).toBeInTheDocument();
+ });
+
+ it("keeps the explanation behind a toggle", async () => {
const { container } = render(
<ReleaseNotice id="t" version="1.0.0" detail="Scores are not comparable.">
Health scores changed in this release.
</ReleaseNotice>,
);
- expect(await screen.findByText("Health scores changed in this release.")).toBeTruthy();
- const details = container.querySelector("details")!;
- expect(details.open).toBe(false);
+ expect(await screen.findByText(/Health scores changed in this release/)).toBeTruthy();
+ expect(container.querySelector("details")!.open).toBe(false);
expect(screen.getByText("What changed")).toBeTruthy();
});
- it("stays dismissed for the same release", async () => {
- const { unmount } = render(<ReleaseNotice id="t" version="1.0.0">Changed.</ReleaseNotice>);
- fireEvent.click(await screen.findByRole("button", { name: "Dismiss" }));
- expect(screen.queryByText("Changed.")).toBeNull();
+ it("remembers dismissal per version", () => {
+ const { unmount } = render(
+ <ReleaseNotice id="a" version="1">
+ Body
+ </ReleaseNotice>,
+ );
+ fireEvent.click(screen.getByRole("button", { name: /dismiss/i }));
+ expect(screen.queryByRole("status")).toBeNull();
unmount();
- render(<ReleaseNotice id="t" version="1.0.0">Changed.</ReleaseNotice>);
- expect(screen.queryByText("Changed.")).toBeNull();
+ render(
+ <ReleaseNotice id="a" version="1">
+ Body
+ </ReleaseNotice>,
+ );
+ expect(screen.queryByRole("status")).toBeNull();
+ render(
+ <ReleaseNotice id="a" version="2">
+ Newer
+ </ReleaseNotice>,
+ );
+ expect(screen.getByText("Newer")).toBeInTheDocument();
+ });
+
+ it("hands dismissal to the host when onDismiss is given", () => {
+ const onDismiss = vi.fn();
+ render(<ReleaseNotice onDismiss={onDismiss}>Body</ReleaseNotice>);
+ fireEvent.click(screen.getByRole("button", { name: /dismiss/i }));
+ expect(onDismiss).toHaveBeenCalledTimes(1);
});
});
diff --git a/packages/ui/__tests__/shared/route-states.test.tsx b/packages/ui/__tests__/shared/route-states.test.tsx
index 77982ac28..306ad6c8e 100644
--- a/packages/ui/__tests__/shared/route-states.test.tsx
+++ b/packages/ui/__tests__/shared/route-states.test.tsx
@@ -24,12 +24,13 @@ describe("RouteError", () => {
describe("RouteNotFound", () => {
it("is neutral, not an alert", () => {
- render(<RouteNotFound title="Repository not found" back={<a href="/">Back</a>} />);
+ render(<RouteNotFound title="Repository not found" links={[<a key="d" href="/">Back</a>]} />);
expect(
screen.getByRole("heading", { level: 1, name: "Repository not found" }),
).toBeInTheDocument();
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
expect(screen.getByRole("link", { name: "Back" })).toBeInTheDocument();
+ expect(screen.getByText("404")).toBeInTheDocument();
});
});
diff --git a/packages/ui/__tests__/shared/theme-toggle.test.tsx b/packages/ui/__tests__/shared/theme-toggle.test.tsx
index db9172f9c..c061dbf93 100644
--- a/packages/ui/__tests__/shared/theme-toggle.test.tsx
+++ b/packages/ui/__tests__/shared/theme-toggle.test.tsx
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";
-import { render, screen, waitFor } from "@testing-library/react";
+import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { ThemeProvider } from "next-themes";
import type { ReactNode } from "react";
import { ThemeToggle } from "../../src/shared/theme-toggle.js";
@@ -52,15 +52,8 @@ describe("ThemeToggle theme default + persistence", () => {
);
await waitFor(() => {
- expect(screen.getByRole("radio", { name: "Light" })).toHaveAttribute(
- "aria-checked",
- "true",
- );
+ expect(screen.getByRole("button", { name: "Switch to dark theme" })).toBeInTheDocument();
});
- expect(screen.getByRole("radio", { name: "Dark" })).toHaveAttribute(
- "aria-checked",
- "false",
- );
// Migration must not write anything for a fresh visitor.
expect(localStorage.getItem(STORAGE_KEY)).not.toBe("dark");
});
@@ -74,10 +67,7 @@ describe("ThemeToggle theme default + persistence", () => {
);
await waitFor(() => {
- expect(screen.getByRole("radio", { name: "Dark" })).toHaveAttribute(
- "aria-checked",
- "true",
- );
+ expect(screen.getByRole("button", { name: "Switch to light theme" })).toBeInTheDocument();
});
expect(localStorage.getItem(STORAGE_KEY)).toBe("dark");
});
@@ -91,10 +81,7 @@ describe("ThemeToggle theme default + persistence", () => {
);
await waitFor(() => {
- expect(screen.getByRole("radio", { name: "Light" })).toHaveAttribute(
- "aria-checked",
- "true",
- );
+ expect(screen.getByRole("button", { name: "Switch to dark theme" })).toBeInTheDocument();
});
expect(localStorage.getItem(STORAGE_KEY)).toBe("light");
});
@@ -110,9 +97,20 @@ describe("ThemeToggle theme default + persistence", () => {
await waitFor(() => {
expect(localStorage.getItem(STORAGE_KEY)).toBe("light");
});
- expect(screen.getByRole("radio", { name: "Light" })).toHaveAttribute(
- "aria-checked",
- "true",
+ expect(
+ screen.getByRole("button", { name: "Switch to dark theme" }),
+ ).toBeInTheDocument();
+ });
+
+ it("switches to the opposite theme on click", async () => {
+ render(
+ <Harness>
+ <ThemeToggle />
+ </Harness>,
);
+ fireEvent.click(await screen.findByRole("button", { name: "Switch to dark theme" }));
+ await waitFor(() => expect(localStorage.getItem(STORAGE_KEY)).toBe("dark"));
+ fireEvent.click(await screen.findByRole("button", { name: "Switch to light theme" }));
+ await waitFor(() => expect(localStorage.getItem(STORAGE_KEY)).toBe("light"));
});
});
diff --git a/packages/ui/src/savings/savings-methodology.tsx b/packages/ui/src/savings/savings-methodology.tsx
index da7efbcaf..ecea68e1b 100644
--- a/packages/ui/src/savings/savings-methodology.tsx
+++ b/packages/ui/src/savings/savings-methodology.tsx
@@ -3,7 +3,7 @@
import * as React from "react";
import { CollapsibleSection } from "../shared/collapsible-section";
-import { DismissibleNotice } from "../shared/dismissible-notice";
+import { ReleaseNotice } from "../shared/release-notice";
/**
* The accounting-method version this build reports under.
@@ -40,10 +40,10 @@ export function SavingsResetNotice({
}: SavingsResetNoticeProps) {
const A = LinkComponent ?? "a";
return (
- <DismissibleNotice
- tone="info"
+ <ReleaseNotice
onDismiss={onDismiss}
dismissLabel="Dismiss the savings accounting notice"
+ title="Savings accounting has been upgraded."
{...(methodologyHref
? {
action: (
@@ -57,14 +57,11 @@ export function SavingsResetNotice({
}
: {})}
>
- <span className="font-medium text-[var(--color-text-primary)]">
- Savings accounting has been upgraded.
- </span>{" "}
Savings are now recorded one event per interaction, with the evidence behind each
figure kept alongside it. Estimates produced by the earlier method could not be
converted, so they were restarted rather than carried over. Your omission history and
everything else in this repository were not deleted.
- </DismissibleNotice>
+ </ReleaseNotice>
);
}
diff --git a/packages/ui/src/shared/release-notice.tsx b/packages/ui/src/shared/release-notice.tsx
index 261fdede7..ed28d8332 100644
--- a/packages/ui/src/shared/release-notice.tsx
+++ b/packages/ui/src/shared/release-notice.tsx
@@ -8,26 +8,35 @@ const STORAGE_PREFIX = "repowise:release-notice-dismissed:";
export interface ReleaseNoticeProps {
/** Stable id for this notice, e.g. `"health-scoring"`. Combined with
* `version` to key the dismissal, so a later release that changes the same
- * thing again shows its notice once more. */
- id: string;
+ * thing again shows its notice once more. Not needed when the host owns
+ * dismissal through `onDismiss`. */
+ id?: string;
/** The release this notice belongs to. Omit only if the notice is not tied
* to one, in which case dismissal is permanent. */
version?: string | null;
- /** The one line the notice reads as. */
+ /** Bold lead sentence, e.g. "Savings accounting has been upgraded." */
+ title?: React.ReactNode;
+ /** The body copy. */
children: React.ReactNode;
- /** The explanation, behind a "What changed" toggle on the same line. */
+ /** The longer explanation, behind a "What changed" toggle. */
detail?: React.ReactNode;
/** The toggle's words, for hosts that localize. */
detailLabel?: string;
hideLabel?: string;
+ /** Optional link or disclosure, e.g. "See what changed". */
+ action?: React.ReactNode;
+ /** Host-owned dismissal (for example scoped per repository). When given the
+ * notice stays visible until the host unmounts it and nothing is stored. */
+ onDismiss?: (() => void) | undefined;
+ dismissLabel?: string;
className?: string;
}
/**
- * A one-time, dismissible "this changed in the release you just installed"
- * line. Lives in the shared package so both the web app and hosted can show
- * it; the web app's `UpgradeBanner` does a different job (an upgrade is
- * *available*) and is not what this replaces.
+ * The one "this changed in the release you installed" announcement, used on
+ * every surface that explains a release-driven change. Warnings and status
+ * belong in `Callout`; an upgrade that is merely available is not this either
+ * (the web app's `UpgradeBanner` does that job).
*
* One line, so it does not outrank the page it sits on; the explanation opens
* in place. The visual is the shared {@link DismissibleNotice}; this owns only
@@ -40,30 +49,42 @@ export interface ReleaseNoticeProps {
export function ReleaseNotice({
id,
version,
+ title,
children,
detail,
detailLabel = "What changed",
hideLabel = "Hide",
+ action,
+ onDismiss,
+ dismissLabel,
className,
}: ReleaseNoticeProps) {
- const storageKey = STORAGE_PREFIX + id + (version ? `:v${version}` : "");
+ const storageKey = id ? STORAGE_PREFIX + id + (version ? `:v${version}` : "") : null;
+ const hostOwned = !!onDismiss || !storageKey;
// Start dismissed so it does not flash in before the stored answer is read.
- const [dismissed, setDismissed] = React.useState(true);
+ const [dismissed, setDismissed] = React.useState(!hostOwned);
React.useEffect(() => {
- if (typeof window === "undefined") return;
+ if (hostOwned || !storageKey) return;
try {
setDismissed(!!window.localStorage.getItem(storageKey));
} catch {
setDismissed(false);
}
- }, [storageKey]);
+ }, [hostOwned, storageKey]);
if (dismissed) return null;
+ const lead = title ? (
+ <>
+ <span className="font-medium text-[var(--color-text-primary)]">{title}</span>{" "}
+ </>
+ ) : null;
+
const dismiss = () => {
+ if (onDismiss) return onDismiss();
try {
- window.localStorage.setItem(storageKey, "1");
+ if (storageKey) window.localStorage.setItem(storageKey, "1");
} catch {
/* localStorage unavailable - hide for this session only. */
}
@@ -71,10 +92,17 @@ export function ReleaseNotice({
};
return (
- <DismissibleNotice onDismiss={dismiss} {...(className ? { className } : {})}>
+ <DismissibleNotice
+ tone="info"
+ onDismiss={dismiss}
+ {...(dismissLabel ? { dismissLabel } : {})}
+ {...(action ? { action } : {})}
+ {...(className ? { className } : {})}
+ >
{detail ? (
<details className="group/release">
<summary className="cursor-pointer list-none rounded focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)]">
+ {lead}
{children}{" "}
<span className="text-[var(--color-accent-primary)] underline-offset-2 hover:underline">
<span className="group-open/release:hidden">{detailLabel}</span>
@@ -84,7 +112,10 @@ export function ReleaseNotice({
<div className="mt-1.5">{detail}</div>
</details>
) : (
- children
+ <>
+ {lead}
+ {children}
+ </>
)}
</DismissibleNotice>
);
diff --git a/packages/ui/src/shared/route-states.tsx b/packages/ui/src/shared/route-states.tsx
index 17cfec4c8..8bddf5190 100644
--- a/packages/ui/src/shared/route-states.tsx
+++ b/packages/ui/src/shared/route-states.tsx
@@ -1,7 +1,8 @@
import * as React from "react";
-import { AlertTriangle, Compass, RefreshCw } from "lucide-react";
+import { AlertTriangle, RefreshCw } from "lucide-react";
import { cn } from "../lib/cn";
import { Button } from "../ui/button";
+import { OrbLoader, ORB_STATE } from "./orb-loader";
const FRAME =
"flex min-h-[60vh] flex-col items-center justify-center gap-4 px-4 py-10 text-center sm:px-6";
@@ -81,40 +82,60 @@ export function RouteError({
export interface RouteNotFoundProps {
title?: string;
description?: string;
- /** Bare icon; tinted tertiary. Defaults to a compass. */
+ /** Mono micro-label above the title. Default "404". */
+ code?: string;
+ /** Replaces the default searching orb. */
icon?: React.ReactNode;
- /** Way back, see `RouteLinkElement`. */
- back?: RouteLinkElement;
+ /** Useful next steps: host links (`<Link>`), rendered as a short list. */
+ links?: RouteLinkElement[];
+ /** Heading above `links`. Default "Try one of these". */
+ linksLabel?: string;
+ /** One-line aside under the links, e.g. the search shortcut. */
+ hint?: React.ReactNode;
className?: string;
}
-/** Route-level 404 body. Neutral, never an error colour. */
+/** Route-level 404 body. Calm and neutral, never an error colour. */
export function RouteNotFound({
title = "Page not found",
description = "The page you are looking for does not exist or has moved.",
+ code = "404",
icon,
- back,
+ links,
+ linksLabel = "Try one of these",
+ hint,
className,
}: RouteNotFoundProps) {
return (
- <div className={cn(FRAME, className)}>
- <span
- aria-hidden
- className="inline-flex text-[var(--color-text-tertiary)] [&_svg]:h-6 [&_svg]:w-6"
- >
- {icon ?? <Compass />}
+ <div className={cn(FRAME, "gap-5", className)}>
+ <span aria-hidden className="inline-flex text-[var(--color-text-tertiary)]">
+ {icon ?? <OrbLoader state={ORB_STATE.searching} size={64} />}
</span>
- <div className="max-w-[52ch] space-y-1">
+ <div className="max-w-[52ch] space-y-1.5">
+ <p className="font-mono text-[10px] uppercase tracking-[0.12em] text-[var(--color-text-tertiary)]">
+ {code}
+ </p>
<h1 className="text-[18px] font-semibold text-[var(--color-text-primary)]">{title}</h1>
<p className="text-xs leading-relaxed text-[var(--color-text-secondary)] [text-wrap:pretty]">
{description}
</p>
</div>
- {back && (
- <Button asChild size="sm" variant="outline" className="h-8">
- {back}
- </Button>
+ {links && links.length > 0 && (
+ <nav aria-label={linksLabel} className="w-full max-w-xs space-y-2">
+ <p className="text-[11px] font-medium text-[var(--color-text-tertiary)]">{linksLabel}</p>
+ <ul className="flex flex-col divide-y divide-[var(--color-border-default)] rounded-md border border-[var(--color-border-default)] text-left text-sm">
+ {links.map((link, i) => (
+ <li
+ key={i}
+ className="[&>a]:flex [&>a]:min-h-10 [&>a]:items-center [&>a]:gap-2 [&>a]:px-3 [&>a]:text-[var(--color-text-primary)] [&>a]:transition-colors [&>a:hover]:bg-[var(--color-bg-wash-hover)] [&>a:focus-visible]:outline-none [&>a:focus-visible]:ring-2 [&>a:focus-visible]:ring-[var(--color-accent-primary)] [&_svg]:h-4 [&_svg]:w-4 [&_svg]:text-[var(--color-text-tertiary)]"
+ >
+ {link}
+ </li>
+ ))}
+ </ul>
+ </nav>
)}
+ {hint && <p className="text-[11px] text-[var(--color-text-tertiary)]">{hint}</p>}
</div>
);
}
diff --git a/packages/ui/src/shared/theme-toggle.tsx b/packages/ui/src/shared/theme-toggle.tsx
index ac9100433..89a6c4d7b 100644
--- a/packages/ui/src/shared/theme-toggle.tsx
+++ b/packages/ui/src/shared/theme-toggle.tsx
@@ -1,26 +1,16 @@
"use client";
/**
- * ThemeToggle — shared segmented Light / Dark control.
+ * ThemeToggle: one icon button that shows the theme in effect and switches to
+ * the other on click.
*
- * Canonical implementation consumed by both `packages/web` and the hosted
- * frontend so the toggle UX stays identical across surfaces. Relies on
- * `next-themes` (a peer dependency of consumers) for state + persistence;
- * this component just calls `setTheme()`.
+ * Relies on `next-themes` (a peer dependency of consumers) for state and
+ * persistence. Deliberately two-state, no "System" option. Consumers set
+ * `enableSystem={false}`; the mount effect migrates any stale persisted
+ * "system" value to light. An explicit light or dark choice is never rewritten.
*
- * Deliberately two-state — no "System" option (product decision: keep the
- * choice explicit). Consumers set `enableSystem={false}` on their provider;
- * the mount effect below migrates any stale persisted "system" value to the
- * light default so pre-simplification visitors don't keep an unknown theme.
- * The migration only fires for non light/dark values, so an explicit Light or
- * Dark choice is never rewritten.
- *
- * The selected option is expressed in CSS off the `dark` class that
- * next-themes writes on `<html>` before first paint, NOT off React state.
- * `useTheme()` returns `undefined` on the server, so a state-driven control
- * renders one frame with neither option selected. Reading the class instead
- * means the first painted frame is already correct. `aria-checked` still
- * waits for mount, because markup cannot be derived from an ancestor class.
+ * Until mounted the button renders a neutral placeholder of the same size, so
+ * server and first client markup match.
*/
import { useEffect, useState } from "react";
@@ -28,77 +18,54 @@ import { useTheme } from "next-themes";
import { Sun, Moon } from "lucide-react";
import { cn } from "../lib/cn";
-const OPTIONS = [
- { value: "light" as const, label: "Light", icon: Sun },
- { value: "dark" as const, label: "Dark", icon: Moon },
-];
-
-const SELECTED =
- "bg-[var(--color-bg-surface)] text-[var(--color-text-primary)] shadow-[var(--shadow-sm)]";
-const UNSELECTED =
- "bg-transparent text-[var(--color-text-secondary)] shadow-none hover:text-[var(--color-text-primary)]";
-const DARK_SELECTED =
- "dark:bg-[var(--color-bg-surface)] dark:text-[var(--color-text-primary)] dark:shadow-[var(--shadow-sm)]";
-const DARK_UNSELECTED =
- "dark:bg-transparent dark:text-[var(--color-text-secondary)] dark:shadow-none dark:hover:text-[var(--color-text-primary)]";
-
export interface ThemeToggleProps {
- /** Hide the text labels and render an icon-only compact control. */
+ /** Accessible name and tooltip while light is active. */
+ switchToDarkLabel?: string;
+ /** Accessible name and tooltip while dark is active. */
+ switchToLightLabel?: string;
+ /** Accepted for backwards compatibility; the control is always icon-only. */
compact?: boolean;
className?: string;
}
-export function ThemeToggle({ compact = false, className }: ThemeToggleProps) {
- const { theme, setTheme } = useTheme();
+const BUTTON =
+ "inline-flex h-8 w-8 items-center justify-center rounded-md text-[var(--color-text-secondary)] transition-colors hover:bg-[var(--color-bg-wash-hover)] hover:text-[var(--color-text-primary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)]";
+
+export function ThemeToggle({
+ switchToDarkLabel = "Switch to dark theme",
+ switchToLightLabel = "Switch to light theme",
+ className,
+}: ThemeToggleProps) {
+ const { theme, resolvedTheme, setTheme } = useTheme();
const [mounted, setMounted] = useState(false);
useEffect(() => {
setMounted(true);
}, []);
- // Migrate a persisted "system" (or any unknown) theme from before the
- // simplification to the explicit light default. Only fires for non
- // light/dark values, so an explicit user choice is never clobbered.
+ // Migrate a persisted "system" (or any unknown) theme to the explicit light
+ // default. Only fires for non light/dark values.
useEffect(() => {
if (mounted && theme !== "light" && theme !== "dark") setTheme("light");
}, [mounted, theme, setTheme]);
+ if (!mounted) {
+ return <span aria-hidden className={cn("inline-block h-8 w-8", className)} />;
+ }
+
+ const isDark = resolvedTheme === "dark";
+ const label = isDark ? switchToLightLabel : switchToDarkLabel;
+ const Icon = isDark ? Moon : Sun;
+
return (
- <div
- role="radiogroup"
- aria-label="Theme preference"
- // No resting border, fill, or shadow: this is a once-per-session
- // control and the permanent track was carrying more weight than the
- // navigation above it. The selected pill is the only ground.
- className={cn("inline-flex items-center gap-1 rounded-lg p-0.5", className)}
+ <button
+ type="button"
+ aria-label={label}
+ title={label}
+ onClick={() => setTheme(isDark ? "light" : "dark")}
+ className={cn(BUTTON, className)}
>
- {OPTIONS.map((opt) => {
- const Icon = opt.icon;
- return (
- <button
- key={opt.value}
- type="button"
- role="radio"
- aria-checked={mounted && theme === opt.value}
- aria-label={opt.label}
- title={opt.label}
- onClick={() => setTheme(opt.value)}
- className={cn(
- "inline-flex items-center justify-center gap-1.5 rounded-md text-xs font-medium transition-colors",
- compact ? "px-1.5 py-1" : "px-3 py-1.5",
- // Selected-ness comes from the ancestor `dark` class, so it is
- // right on the first painted frame. Each option is styled
- // selected in its own theme and quiet in the other.
- opt.value === "light"
- ? [SELECTED, DARK_UNSELECTED]
- : [UNSELECTED, DARK_SELECTED],
- )}
- >
- <Icon className="h-3.5 w-3.5 shrink-0" />
- {!compact && opt.label}
- </button>
- );
- })}
- </div>
+ <Icon className="h-3.5 w-3.5 shrink-0" aria-hidden />
+ </button>
);
}
diff --git a/packages/web/messages/en.json b/packages/web/messages/en.json
index 3445984a2..1be12b0a3 100644
--- a/packages/web/messages/en.json
+++ b/packages/web/messages/en.json
@@ -19,6 +19,8 @@
"switched": "Language switched to {language}"
},
"shell": {
+ "switchToDarkTheme": "Switch to dark theme",
+ "switchToLightTheme": "Switch to light theme",
"skipToContent": "Skip to content",
"expandSidebar": "Expand sidebar",
"collapseSidebar": "Collapse sidebar",
@@ -153,6 +155,11 @@
"settingsErrorFallback": "Could not load settings. The backend may be unavailable.",
"notFoundTitle": "Page not found",
"notFoundBody": "The page you requested doesn't exist. It may have been moved or never existed.",
+ "notFoundLinks": "Try one of these",
+ "notFoundSearchHint": "Or press <kbd>Ctrl K</kbd> (<kbd>⌘ K</kbd> on Mac) to search.",
+ "repoOverview": "Repository overview",
+ "repoCodeHealth": "Code health",
+ "repoDocs": "Docs",
"backToDashboard": "Back to dashboard",
"errorTitle": "Something went wrong",
"errorFallback": "An unexpected error occurred. Please try again.",
diff --git a/packages/web/messages/zh-CN.json b/packages/web/messages/zh-CN.json
index 7fef0e95d..d6c326654 100644
--- a/packages/web/messages/zh-CN.json
+++ b/packages/web/messages/zh-CN.json
@@ -19,6 +19,8 @@
"switched": "语言已切换为{language}"
},
"shell": {
+ "switchToDarkTheme": "切换到深色主题",
+ "switchToLightTheme": "切换到浅色主题",
"skipToContent": "跳到主内容",
"expandSidebar": "展开侧边栏",
"collapseSidebar": "收起侧边栏",
@@ -153,6 +155,11 @@
"settingsErrorFallback": "无法加载设置,后端可能不可用。",
"notFoundTitle": "页面不存在",
"notFoundBody": "你请求的页面不存在,可能已被移动,或从未存在。",
+ "notFoundLinks": "试试这些入口",
+ "notFoundSearchHint": "或按 <kbd>Ctrl K</kbd>(Mac 上为 <kbd>⌘ K</kbd>)进行搜索。",
+ "repoOverview": "仓库概览",
+ "repoCodeHealth": "代码健康",
+ "repoDocs": "文档",
"backToDashboard": "返回仪表盘",
"errorTitle": "出错了",
"errorFallback": "发生了意外错误,请重试。",
diff --git a/packages/web/src/app/not-found.tsx b/packages/web/src/app/not-found.tsx
index f5fb941a4..1d99a9775 100644
--- a/packages/web/src/app/not-found.tsx
+++ b/packages/web/src/app/not-found.tsx
@@ -1,5 +1,5 @@
import Link from "next/link";
-import { ChevronLeft } from "lucide-react";
+import { LayoutDashboard } from "lucide-react";
import { getTranslations } from "next-intl/server";
import { RouteNotFound } from "@repowise-dev/ui/shared/route-states";
@@ -10,12 +10,20 @@ export default async function NotFound() {
<RouteNotFound
title={t("notFoundTitle")}
description={t("notFoundBody")}
- back={
- <Link href="/">
- <ChevronLeft className="h-4 w-4" aria-hidden />
- {t("backToDashboard")}
- </Link>
- }
+ linksLabel={t("notFoundLinks")}
+ links={[
+ <Link key="dashboard" href="/">
+ <LayoutDashboard aria-hidden />
+ {t("dashboard")}
+ </Link>,
+ ]}
+ hint={t.rich("notFoundSearchHint", {
+ kbd: (chunks) => (
+ <kbd className="rounded border border-[var(--color-border-default)] px-1 font-mono text-[10px]">
+ {chunks}
+ </kbd>
+ ),
+ })}
/>
);
}
diff --git a/packages/web/src/app/repos/[id]/code-health/page.tsx b/packages/web/src/app/repos/[id]/code-health/page.tsx
index 130cb57f8..ea037fb08 100644
--- a/packages/web/src/app/repos/[id]/code-health/page.tsx
+++ b/packages/web/src/app/repos/[id]/code-health/page.tsx
@@ -239,6 +239,7 @@ const CHURN_POINT_LIMIT = 5000;
export default function CodeHealthPage() {
const t = useTranslations("views.codeHealth");
+ const tc = useTranslations("common");
const params = useParams<{ id: string }>();
const router = useRouter();
const searchParams = useSearchParams();
@@ -551,6 +552,7 @@ export default function CodeHealthPage() {
detail={t("coChangeNoticeBody")}
detailLabel={t("coChangeNoticeMore")}
hideLabel={t("coChangeNoticeLess")}
+ dismissLabel={tc("dismiss")}
>
{t("coChangeNoticeTitle")}
</ReleaseNotice>
diff --git a/packages/web/src/app/repos/[id]/not-found.tsx b/packages/web/src/app/repos/[id]/not-found.tsx
index f1fee77ab..9121344c7 100644
--- a/packages/web/src/app/repos/[id]/not-found.tsx
+++ b/packages/web/src/app/repos/[id]/not-found.tsx
@@ -1,22 +1,50 @@
+"use client";
+
import Link from "next/link";
-import { ChevronLeft, Home } from "lucide-react";
-import { getTranslations } from "next-intl/server";
+import { useParams } from "next/navigation";
+import { BookOpen, HeartPulse, Home, LayoutDashboard } from "lucide-react";
+import { useTranslations } from "next-intl";
import { RouteNotFound } from "@repowise-dev/ui/shared/route-states";
-export default async function RepoNotFound() {
- const t = await getTranslations("errors");
+export default function RepoNotFound() {
+ const t = useTranslations("errors");
+ const params = useParams<{ id?: string }>();
+ const base = params?.id ? `/repos/${params.id}` : null;
return (
<RouteNotFound
title={t("repoNotFoundTitle")}
description={t("repoNotFoundBody")}
- icon={<Home />}
- back={
- <Link href="/">
- <ChevronLeft className="h-4 w-4" aria-hidden />
- {t("backToDashboard")}
- </Link>
- }
+ linksLabel={t("notFoundLinks")}
+ links={[
+ ...(base
+ ? [
+ <Link key="overview" href={`${base}/overview`}>
+ <Home aria-hidden />
+ {t("repoOverview")}
+ </Link>,
+ <Link key="health" href={`${base}/code-health`}>
+ <HeartPulse aria-hidden />
+ {t("repoCodeHealth")}
+ </Link>,
+ <Link key="docs" href={`${base}/docs`}>
+ <BookOpen aria-hidden />
+ {t("repoDocs")}
+ </Link>,
+ ]
+ : []),
+ <Link key="dashboard" href="/">
+ <LayoutDashboard aria-hidden />
+ {t("dashboard")}
+ </Link>,
+ ]}
+ hint={t.rich("notFoundSearchHint", {
+ kbd: (chunks) => (
+ <kbd className="rounded border border-[var(--color-border-default)] px-1 font-mono text-[10px]">
+ {chunks}
+ </kbd>
+ ),
+ })}
/>
);
}
diff --git a/packages/web/src/components/layout/language-switcher.tsx b/packages/web/src/components/layout/language-switcher.tsx
index 6389166d4..4fdedd9af 100644
--- a/packages/web/src/components/layout/language-switcher.tsx
+++ b/packages/web/src/components/layout/language-switcher.tsx
@@ -1,7 +1,8 @@
"use client";
/**
- * LanguageSwitcher — the 中 / EN control in the shell tool area.
+ * LanguageSwitcher — one compact button showing the current language that
+ * opens a menu of every locale in `LOCALES`.
*
* Switching is cookie-first: `NEXT_LOCALE` is what the server reads on the
* next request, so writing it and calling `router.refresh()` re-renders the
@@ -16,7 +17,8 @@
import * as React from "react";
import { useLocale, useTranslations } from "next-intl";
import { useRouter } from "next/navigation";
-import { Languages } from "lucide-react";
+import { Check, Globe } from "lucide-react";
+import { Popover, PopoverContent, PopoverTrigger } from "@repowise-dev/ui/ui/popover";
import { toast } from "sonner";
import { cn } from "@/lib/utils/cn";
import {
@@ -31,19 +33,20 @@ import {
/** One year, in seconds. */
const COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
-/** Short marks for the compact control, in each language's own script. */
+/** Short marks for the trigger, in each language's own script. */
const SHORT_LABEL: Record<Locale, string> = {
en: "EN",
- "zh-CN": "中",
+ "zh-CN": "中文",
};
export interface LanguageSwitcherProps {
- /** Icon-scale control: short marks and no icon, for the sidebar footer. */
+ /** Globe only, for the 56px collapsed sidebar where the mark does not fit. */
compact?: boolean;
className?: string;
}
-export function LanguageSwitcher({ compact = false, className }: LanguageSwitcherProps) {
+export function LanguageSwitcher({ compact, className }: LanguageSwitcherProps) {
+ const [open, setOpen] = React.useState(false);
const active = useLocale() as Locale;
const t = useTranslations("language");
const router = useRouter();
@@ -78,6 +81,7 @@ export function LanguageSwitcher({ compact = false, className }: LanguageSwitche
}, []);
const select = (next: Locale) => {
+ setOpen(false);
if (next === active || pending) return;
document.cookie = cookieFor(next);
try {
@@ -93,41 +97,42 @@ export function LanguageSwitcher({ compact = false, className }: LanguageSwitche
};
return (
- <div
- role="radiogroup"
- aria-label={t("label")}
- className={cn("inline-flex items-center gap-1 rounded-lg p-0.5", className)}
- >
- {!compact && (
- <Languages
- className="mx-0.5 h-3.5 w-3.5 shrink-0 text-[var(--color-text-tertiary)]"
- aria-hidden
- />
- )}
- {LOCALES.map((locale) => {
- const selected = locale === active;
- return (
- <button
- key={locale}
- type="button"
- role="radio"
- aria-checked={selected}
- aria-label={LOCALE_LABELS[locale]}
- title={LOCALE_LABELS[locale]}
- onClick={() => select(locale)}
- className={cn(
- "inline-flex items-center justify-center rounded-md text-xs font-medium transition-colors",
- compact ? "px-1.5 py-1" : "px-2.5 py-1.5",
- selected
- ? "bg-[var(--color-bg-surface)] text-[var(--color-text-primary)] shadow-[var(--shadow-sm)]"
- : "bg-transparent text-[var(--color-text-secondary)] shadow-none hover:text-[var(--color-text-primary)]",
- )}
- >
- {compact ? SHORT_LABEL[locale] : LOCALE_LABELS[locale]}
- </button>
- );
- })}
- </div>
+ <Popover open={open} onOpenChange={setOpen}>
+ <PopoverTrigger asChild>
+ <button
+ type="button"
+ aria-label={`${t("label")}: ${LOCALE_LABELS[active]}`}
+ className={cn(
+ "inline-flex h-8 min-w-8 items-center justify-center gap-1 rounded-md px-1.5 text-xs font-medium text-[var(--color-text-secondary)] transition-colors hover:bg-[var(--color-bg-wash-hover)] hover:text-[var(--color-text-primary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)]",
+ className,
+ )}
+ >
+ <Globe className="h-3.5 w-3.5 shrink-0" aria-hidden />
+ {!compact && <span lang={active}>{SHORT_LABEL[active]}</span>}
+ </button>
+ </PopoverTrigger>
+ <PopoverContent align="start" side="top" className="w-44 p-1">
+ <ul aria-label={t("label")} className="flex flex-col">
+ {LOCALES.map((locale) => {
+ const selected = locale === active;
+ return (
+ <li key={locale}>
+ <button
+ type="button"
+ aria-current={selected ? "true" : undefined}
+ lang={locale}
+ onClick={() => select(locale)}
+ className="flex min-h-8 w-full items-center justify-between gap-2 rounded px-2 text-left text-sm text-[var(--color-text-primary)] hover:bg-[var(--color-bg-wash-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--color-accent-primary)]"
+ >
+ {LOCALE_LABELS[locale]}
+ {selected && <Check className="h-3.5 w-3.5" aria-hidden />}
+ </button>
+ </li>
+ );
+ })}
+ </ul>
+ </PopoverContent>
+ </Popover>
);
}
diff --git a/packages/web/src/components/layout/mobile-nav.tsx b/packages/web/src/components/layout/mobile-nav.tsx
index 380c15a67..c3c7430b1 100644
--- a/packages/web/src/components/layout/mobile-nav.tsx
+++ b/packages/web/src/components/layout/mobile-nav.tsx
@@ -280,8 +280,11 @@ export function MobileNav({ repos = [], workspace }: MobileNavProps) {
<div className="flex items-center justify-between gap-2">
<VersionFooter />
<div className="flex items-center gap-1">
- <LanguageSwitcher compact />
- <ThemeToggle compact />
+ <LanguageSwitcher />
+ <ThemeToggle
+ switchToDarkLabel={ts("switchToDarkTheme")}
+ switchToLightLabel={ts("switchToLightTheme")}
+ />
</div>
</div>
</div>
diff --git a/packages/web/src/components/layout/sidebar.tsx b/packages/web/src/components/layout/sidebar.tsx
index 3681a8164..cbd84a409 100644
--- a/packages/web/src/components/layout/sidebar.tsx
+++ b/packages/web/src/components/layout/sidebar.tsx
@@ -457,7 +457,10 @@ export function Sidebar({
{isIconOnly ? (
<div className="flex flex-col items-center gap-1 border-t border-[var(--color-border-default)] py-1.5">
<LanguageSwitcher compact />
- <ThemeToggle compact />
+ <ThemeToggle
+ switchToDarkLabel={ts("switchToDarkTheme")}
+ switchToLightLabel={ts("switchToLightTheme")}
+ />
</div>
) : (
<div className="flex flex-col gap-2 border-t border-[var(--color-border-default)] px-3 py-2">
@@ -468,8 +471,11 @@ export function Sidebar({
<div className="flex items-center justify-between gap-2">
<VersionFooter />
<div className="flex items-center gap-1">
- <LanguageSwitcher compact />
- <ThemeToggle compact />
+ <LanguageSwitcher />
+ <ThemeToggle
+ switchToDarkLabel={ts("switchToDarkTheme")}
+ switchToLightLabel={ts("switchToLightTheme")}
+ />
</div>
</div>
</div>