fix(webui): polish mobile settings and context interactions
This commit is contained in:
1 parent
827dbe137b
commit
f5c6be2608
5 files changed
+553
-80
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { useRef } from "react";
|
||||
import { useRef, useState } from "react";
|
||||
import {
|
||||
Activity,
|
||||
Info,
|
||||
@@ -23,12 +23,8 @@ import {
|
||||
} from "@/components/SidebarSelectionHighlight";
|
||||
import { isCapabilitySection, type SettingsSectionKey } from "@/components/settings/contracts";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Sheet, SheetContent, SheetTitle, SheetTrigger } from "@/components/ui/sheet";
|
||||
import { useMediaQuery } from "@/hooks/useMediaQuery";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const SETTINGS_NAV_ITEMS: Array<{ key: SettingsSectionKey; icon: LucideIcon; fallback: string }> = [
|
||||
@@ -49,17 +45,7 @@ export function standaloneSectionTitle(section: SettingsSectionKey): string {
|
||||
return SETTINGS_NAV_ITEMS.find((item) => item.key === section)?.fallback ?? "Settings";
|
||||
}
|
||||
|
||||
export function SettingsSidebar({
|
||||
activeSection,
|
||||
onSelectSection,
|
||||
onBackToChat,
|
||||
onLogout,
|
||||
hostChromeInset,
|
||||
onRestart,
|
||||
isRestarting,
|
||||
restartPending,
|
||||
isNativeHost,
|
||||
}: {
|
||||
interface SettingsSidebarProps {
|
||||
activeSection: SettingsSectionKey;
|
||||
onSelectSection: (section: SettingsSectionKey) => void;
|
||||
onBackToChat: () => void;
|
||||
@@ -69,8 +55,22 @@ export function SettingsSidebar({
|
||||
isRestarting?: boolean;
|
||||
restartPending?: boolean;
|
||||
isNativeHost?: boolean;
|
||||
}) {
|
||||
}
|
||||
|
||||
export function SettingsSidebar(props: SettingsSidebarProps) {
|
||||
const {
|
||||
activeSection,
|
||||
onSelectSection,
|
||||
onBackToChat,
|
||||
onLogout,
|
||||
hostChromeInset,
|
||||
onRestart,
|
||||
isRestarting,
|
||||
restartPending,
|
||||
isNativeHost,
|
||||
} = props;
|
||||
const { t } = useTranslation();
|
||||
const mobile = useMediaQuery("(max-width: 1023px)");
|
||||
const restartLabel = isRestarting
|
||||
? t(isNativeHost ? "app.system.restartingEngine" : "app.system.restarting")
|
||||
: t("app.system.restartAction");
|
||||
@@ -78,11 +78,15 @@ export function SettingsSidebar({
|
||||
const activeNavItemRef = useRef<HTMLButtonElement>(null);
|
||||
const activeItem = SETTINGS_NAV_ITEMS.find((item) => item.key === navSection)
|
||||
?? SETTINGS_NAV_ITEMS[0];
|
||||
const ActiveIcon = activeItem.icon;
|
||||
const activeLabel = t(`settings.nav.${activeItem.key}`, {
|
||||
defaultValue: activeItem.fallback,
|
||||
});
|
||||
|
||||
if (mobile) {
|
||||
return <MobileSettingsNavigation {...props} navSection={navSection}
|
||||
activeLabel={activeLabel} restartLabel={restartLabel} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<aside
|
||||
className={cn(
|
||||
@@ -106,46 +110,6 @@ export function SettingsSidebar({
|
||||
aria-label={t("settings.sidebar.ariaLabel")}
|
||||
className="w-full"
|
||||
>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`${t("settings.sidebar.title")}: ${activeLabel}`}
|
||||
className="touch-target flex h-11 w-full items-center gap-2.5 rounded-control bg-sidebar-accent px-3 text-left text-[13px] leading-5 font-normal text-foreground transition-colors settings-hover lg:hidden"
|
||||
>
|
||||
<ActiveIcon className="h-4 w-4 shrink-0" strokeWidth={2} aria-hidden />
|
||||
<span className="min-w-0 flex-1 truncate">{activeLabel}</span>
|
||||
<ChevronDown className="h-4 w-4 shrink-0 text-sidebar-content" aria-hidden />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent
|
||||
align="start"
|
||||
sideOffset={6}
|
||||
className="w-[var(--radix-dropdown-menu-trigger-width)] max-w-[calc(100vw-1.5rem)]"
|
||||
>
|
||||
{SETTINGS_NAV_ITEMS.map(({ key, icon: Icon, fallback }) => {
|
||||
const active = key === navSection;
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={key}
|
||||
aria-current={active ? "page" : undefined}
|
||||
onSelect={() => onSelectSection(key)}
|
||||
className={cn(
|
||||
"flex h-10 cursor-default items-center gap-2.5 px-2.5 text-[13px] leading-5 font-normal",
|
||||
active && "bg-sidebar-accent text-foreground focus:bg-sidebar-accent",
|
||||
)}
|
||||
>
|
||||
<Icon className="h-4 w-4 shrink-0" strokeWidth={2} aria-hidden />
|
||||
<span className="min-w-0 flex-1 truncate">
|
||||
{t(`settings.nav.${key}`, { defaultValue: fallback })}
|
||||
</span>
|
||||
{active ? <Check className="h-4 w-4 shrink-0" aria-hidden /> : null}
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
})}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
<SidebarSelectionHighlight
|
||||
targetRef={activeNavItemRef}
|
||||
activeId={navSection}
|
||||
@@ -219,3 +183,102 @@ export function SettingsSidebar({
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
|
||||
// Mount only on narrow screens so switching to desktop also releases the sheet's focus/pointer lock.
|
||||
function MobileSettingsNavigation({
|
||||
navSection,
|
||||
activeLabel,
|
||||
restartLabel,
|
||||
onSelectSection,
|
||||
onBackToChat,
|
||||
hostChromeInset,
|
||||
onRestart,
|
||||
isRestarting,
|
||||
restartPending,
|
||||
}: SettingsSidebarProps & {
|
||||
navSection: SettingsSectionKey;
|
||||
activeLabel: string;
|
||||
restartLabel: string;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const restartAction = onRestart ? (
|
||||
<Button type="button" variant="ghost" disabled={isRestarting}
|
||||
onClick={() => { setOpen(false); onRestart(); }}
|
||||
className={cn("h-11 shrink-0 gap-2 px-3 text-sm font-normal",
|
||||
restartPending && !isRestarting
|
||||
? "text-orange-600 hover:text-orange-700 dark:text-orange-400 dark:hover:text-orange-300"
|
||||
: "text-muted-foreground hover:text-foreground")}
|
||||
>
|
||||
{isRestarting ? <Loader2 className="h-4 w-4 animate-spin" aria-hidden />
|
||||
: <RotateCcw className="h-4 w-4" aria-hidden />}
|
||||
{restartLabel}
|
||||
</Button>
|
||||
) : null;
|
||||
|
||||
return (
|
||||
<aside className={cn("shrink-0 border-b border-border/50 bg-settings-canvas",
|
||||
hostChromeInset ? "pt-10" : "pt-[env(safe-area-inset-top)]")}
|
||||
>
|
||||
<div className="grid h-14 grid-cols-[2.75rem_minmax(0,1fr)_2.75rem] items-center px-3">
|
||||
<Button type="button" variant="ghost" onClick={onBackToChat}
|
||||
aria-label={t("settings.backToChat")}
|
||||
className="h-11 w-11 rounded-full p-0 text-sidebar-content"
|
||||
>
|
||||
<ChevronLeft className="h-5 w-5" aria-hidden />
|
||||
</Button>
|
||||
<Sheet open={open} onOpenChange={setOpen}>
|
||||
<SheetTrigger asChild>
|
||||
<Button type="button" variant="ghost"
|
||||
aria-label={`${t("settings.sidebar.title")}: ${activeLabel}`}
|
||||
className="h-11 min-w-0 max-w-full justify-self-center gap-1.5 px-2 text-base font-medium"
|
||||
>
|
||||
<span className="truncate">{activeLabel}</span>
|
||||
<ChevronDown className="h-3.5 w-3.5 shrink-0 text-muted-foreground" aria-hidden />
|
||||
</Button>
|
||||
</SheetTrigger>
|
||||
<SheetContent side="bottom" showCloseButton={false} aria-describedby={undefined}
|
||||
className="mx-auto max-h-[85dvh] max-w-md gap-0 rounded-t-3xl px-3 pt-2 pb-[max(0.75rem,env(safe-area-inset-bottom))] data-[state=open]:duration-300 data-[state=closed]:duration-200"
|
||||
>
|
||||
<div className="flex shrink-0 items-center justify-between gap-3 px-3 pb-2">
|
||||
<SheetTitle className="text-base font-medium">{t("settings.sidebar.title")}</SheetTitle>
|
||||
<Button type="button" variant="ghost" onClick={() => setOpen(false)}
|
||||
className="-mr-2 h-11 px-2 text-sm font-normal text-muted-foreground"
|
||||
>{t("common.close")}</Button>
|
||||
</div>
|
||||
<div className="min-h-0 overflow-y-auto overscroll-contain">
|
||||
<nav aria-label={t("settings.sidebar.ariaLabel")} className="space-y-0.5">
|
||||
{SETTINGS_NAV_ITEMS.map(({ key, icon: Icon, fallback }) => {
|
||||
const active = key === navSection;
|
||||
return (
|
||||
<Button key={key} type="button" variant="ghost"
|
||||
aria-current={active ? "page" : undefined}
|
||||
onClick={() => { setOpen(false); onSelectSection(key); }}
|
||||
className={cn("h-11 w-full justify-start gap-3 rounded-xl px-3 text-sm font-normal",
|
||||
active ? "bg-sidebar-accent text-foreground" : "text-sidebar-content")}
|
||||
>
|
||||
<Icon className="h-[18px] w-[18px] shrink-0" aria-hidden />
|
||||
<span className="min-w-0 flex-1 truncate text-left">
|
||||
{t(`settings.nav.${key}`, { defaultValue: fallback })}
|
||||
</span>
|
||||
{active ? <Check className="h-4 w-4 shrink-0" aria-hidden /> : null}
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
{restartAction ? <div className="mt-2 border-t border-border/50 pt-2">{restartAction}</div> : null}
|
||||
</div>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
</div>
|
||||
{onRestart && (restartPending || isRestarting) ? (
|
||||
<div className="flex min-h-11 items-center justify-between gap-2 px-4 pb-1">
|
||||
<p role="status" className="text-xs leading-5 text-muted-foreground">
|
||||
{isRestarting ? restartLabel : t("settings.status.savedRestartApply")}
|
||||
</p>
|
||||
{restartAction}
|
||||
</div>
|
||||
) : null}
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user