mirror of
https://github.com/multica-ai/multica.git
synced 2026-08-01 01:16:17 +02:00
- Rename appearance-tab → preferences-tab; AppearanceTab → PreferencesTab - i18n top-level key appearance → preferences; tab label "Appearance" → "Preferences" / "偏好设置" - Swap icon Palette → SlidersHorizontal (preferences semantic) - SettingsPage: read active tab from ?tab= via NavigationAdapter, write back with replace() on change; whitelist valid tabs (incl. desktop extras daemon/updates), unknown values fall back to profile - Update conventions.mdx (en + zh) references to renamed file and i18n key Why preferences over appearance: the tab held both theme and language; "Appearance" semantically excludes localization. "Preferences" follows Linear/Slack/Discord and leaves room to add timezone/date format later. Why query param over path: settings tabs are UI modifier state, not resources; query persistence keeps the existing single Next.js route file and desktop memory router unchanged, gives a natural fallback for unknown values, and avoids 404 risk. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
160 lines
5.5 KiB
TypeScript
160 lines
5.5 KiB
TypeScript
"use client";
|
|
|
|
import React from "react";
|
|
import {
|
|
User,
|
|
SlidersHorizontal,
|
|
Key,
|
|
Settings,
|
|
Users,
|
|
FolderGit2,
|
|
FlaskConical,
|
|
Bell,
|
|
} from "lucide-react";
|
|
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@multica/ui/components/ui/tabs";
|
|
import { useCurrentWorkspace } from "@multica/core/paths";
|
|
import { useNavigation } from "../../navigation";
|
|
import { AccountTab } from "./account-tab";
|
|
import { PreferencesTab } from "./preferences-tab";
|
|
import { TokensTab } from "./tokens-tab";
|
|
import { WorkspaceTab } from "./workspace-tab";
|
|
import { MembersTab } from "./members-tab";
|
|
import { RepositoriesTab } from "./repositories-tab";
|
|
import { LabsTab } from "./labs-tab";
|
|
import { NotificationsTab } from "./notifications-tab";
|
|
import { useT } from "../../i18n";
|
|
|
|
const ACCOUNT_TAB_KEYS = ["profile", "preferences", "notifications", "tokens"] as const;
|
|
const ACCOUNT_TAB_ICONS = {
|
|
profile: User,
|
|
preferences: SlidersHorizontal,
|
|
notifications: Bell,
|
|
tokens: Key,
|
|
} as const;
|
|
|
|
const WORKSPACE_TAB_KEYS = ["general", "repositories", "labs", "members"] as const;
|
|
const WORKSPACE_TAB_VALUES = {
|
|
general: "workspace",
|
|
repositories: "repositories",
|
|
labs: "labs",
|
|
members: "members",
|
|
} as const;
|
|
const WORKSPACE_TAB_ICONS = {
|
|
general: Settings,
|
|
repositories: FolderGit2,
|
|
labs: FlaskConical,
|
|
members: Users,
|
|
} as const;
|
|
|
|
const DEFAULT_TAB = "profile";
|
|
const TAB_QUERY_KEY = "tab";
|
|
|
|
export interface ExtraSettingsTab {
|
|
value: string;
|
|
label: string;
|
|
icon: React.ComponentType<{ className?: string }>;
|
|
content: React.ReactNode;
|
|
}
|
|
|
|
interface SettingsPageProps {
|
|
/** Additional tabs injected by platform (e.g. desktop daemon settings) */
|
|
extraAccountTabs?: ExtraSettingsTab[];
|
|
}
|
|
|
|
export function SettingsPage({ extraAccountTabs }: SettingsPageProps = {}) {
|
|
const { t } = useT("settings");
|
|
const workspaceName = useCurrentWorkspace()?.name;
|
|
const navigation = useNavigation();
|
|
|
|
// Whitelist of valid tab values; unknown ?tab=… values silently fall back to
|
|
// the default. Whitelisting also blocks junk like ?tab=<script> from
|
|
// surfacing in the DOM via Radix Tabs internals.
|
|
const validTabs = React.useMemo(
|
|
() =>
|
|
new Set<string>([
|
|
...ACCOUNT_TAB_KEYS,
|
|
...Object.values(WORKSPACE_TAB_VALUES),
|
|
...(extraAccountTabs?.map((tab) => tab.value) ?? []),
|
|
]),
|
|
[extraAccountTabs],
|
|
);
|
|
|
|
const tabFromUrl = navigation.searchParams.get(TAB_QUERY_KEY);
|
|
const activeTab =
|
|
tabFromUrl && validTabs.has(tabFromUrl) ? tabFromUrl : DEFAULT_TAB;
|
|
|
|
// replace (not push) so settings tab switches don't pollute browser history.
|
|
// Preserve any other query params the page may carry.
|
|
const handleTabChange = (next: string) => {
|
|
const params = new URLSearchParams(navigation.searchParams);
|
|
params.set(TAB_QUERY_KEY, next);
|
|
navigation.replace(`${navigation.pathname}?${params.toString()}`);
|
|
};
|
|
|
|
return (
|
|
<Tabs
|
|
value={activeTab}
|
|
onValueChange={handleTabChange}
|
|
orientation="vertical"
|
|
className="flex-1 min-h-0 gap-0 flex flex-col md:flex-row md:overflow-hidden overflow-y-auto"
|
|
>
|
|
{/* Left nav (stacks on top on mobile, sidebar on md+) */}
|
|
<div className="shrink-0 md:w-52 border-b md:border-b-0 md:border-r md:overflow-y-auto p-3 md:p-4">
|
|
<h1 className="text-sm font-semibold mb-4 px-2">{t(($) => $.page.title)}</h1>
|
|
<TabsList variant="line" className="flex-col items-stretch w-full">
|
|
{/* My Account group */}
|
|
<span className="px-2 pb-1 pt-2 text-xs font-medium text-muted-foreground">
|
|
{t(($) => $.page.my_account)}
|
|
</span>
|
|
{ACCOUNT_TAB_KEYS.map((key) => {
|
|
const Icon = ACCOUNT_TAB_ICONS[key];
|
|
return (
|
|
<TabsTrigger key={key} value={key}>
|
|
<Icon className="h-4 w-4" />
|
|
{t(($) => $.page.tabs[key])}
|
|
</TabsTrigger>
|
|
);
|
|
})}
|
|
{extraAccountTabs?.map((tab) => (
|
|
<TabsTrigger key={tab.value} value={tab.value}>
|
|
<tab.icon className="h-4 w-4" />
|
|
{tab.label}
|
|
</TabsTrigger>
|
|
))}
|
|
|
|
{/* Workspace group */}
|
|
<span className="px-2 pb-1 pt-4 text-xs font-medium text-muted-foreground truncate">
|
|
{workspaceName ?? t(($) => $.page.workspace_fallback)}
|
|
</span>
|
|
{WORKSPACE_TAB_KEYS.map((key) => {
|
|
const Icon = WORKSPACE_TAB_ICONS[key];
|
|
return (
|
|
<TabsTrigger key={key} value={WORKSPACE_TAB_VALUES[key]}>
|
|
<Icon className="h-4 w-4" />
|
|
{t(($) => $.page.tabs[key])}
|
|
</TabsTrigger>
|
|
);
|
|
})}
|
|
</TabsList>
|
|
</div>
|
|
|
|
{/* Right content */}
|
|
<div className="flex-1 min-w-0 md:overflow-y-auto">
|
|
<div className="w-full max-w-3xl mx-auto p-4 md:p-6">
|
|
<TabsContent value="profile"><AccountTab /></TabsContent>
|
|
<TabsContent value="preferences"><PreferencesTab /></TabsContent>
|
|
<TabsContent value="notifications"><NotificationsTab /></TabsContent>
|
|
<TabsContent value="tokens"><TokensTab /></TabsContent>
|
|
<TabsContent value="workspace"><WorkspaceTab /></TabsContent>
|
|
<TabsContent value="repositories"><RepositoriesTab /></TabsContent>
|
|
<TabsContent value="labs"><LabsTab /></TabsContent>
|
|
<TabsContent value="members"><MembersTab /></TabsContent>
|
|
{extraAccountTabs?.map((tab) => (
|
|
<TabsContent key={tab.value} value={tab.value}>{tab.content}</TabsContent>
|
|
))}
|
|
</div>
|
|
</div>
|
|
</Tabs>
|
|
);
|
|
}
|