From 15976ac559d5a94afa0fd7bc2bf7ad665f63a02e Mon Sep 17 00:00:00 2001 From: chengyongru Date: Mon, 14 Sep 2026 11:13:40 +0800 Subject: [PATCH] fix(webui): streamline the connection screen --- webui/src/App.tsx | 198 +++++++++++++--------- webui/src/components/LanguageSwitcher.tsx | 20 ++- webui/src/components/ui/select.tsx | 7 +- webui/src/i18n/locales/en/common.json | 9 +- webui/src/i18n/locales/es/common.json | 9 +- webui/src/i18n/locales/fr/common.json | 9 +- webui/src/i18n/locales/id/common.json | 9 +- webui/src/i18n/locales/ja/common.json | 9 +- webui/src/i18n/locales/ko/common.json | 9 +- webui/src/i18n/locales/pt-BR/common.json | 9 +- webui/src/i18n/locales/vi/common.json | 9 +- webui/src/i18n/locales/zh-CN/common.json | 9 +- webui/src/i18n/locales/zh-TW/common.json | 9 +- webui/src/tests/app-layout.test.tsx | 120 +++++++++++-- 14 files changed, 308 insertions(+), 127 deletions(-) diff --git a/webui/src/App.tsx b/webui/src/App.tsx index fd398e63f..02e7f46ef 100644 --- a/webui/src/App.tsx +++ b/webui/src/App.tsx @@ -8,10 +8,11 @@ import { useState, type ReactNode, } from "react"; -import { Eye, EyeOff, Moon, ShieldCheck, Sun, X } from "lucide-react"; -import { useTranslation } from "react-i18next"; +import { ArrowRight, ChevronDown, Eye, EyeOff, Moon, ShieldCheck, Sun, X } from "lucide-react"; +import { Trans, useTranslation } from "react-i18next"; import { channelUiPresentation } from "@/channel-plugins/registry"; import { Sidebar } from "@/components/Sidebar"; +import { LanguageSwitcher } from "@/components/LanguageSwitcher"; import { SidebarResizeHandle, SIDEBAR_MIN_WIDTH, SIDEBAR_MAX_WIDTH } from "@/components/SidebarResizeHandle"; import { matchSidebarShortcut } from "@/lib/sidebar-shortcuts"; import type { SidebarDeleteItem } from "@/components/ChatList"; @@ -75,6 +76,7 @@ import type { } from "@/lib/types"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; +import { Disclosure } from "@/components/ui/disclosure"; import { fetchPairingRequests, fetchSettings, @@ -364,10 +366,17 @@ function AuthForm({ ); const errorMessage = validationError ? t(`app.auth.${validationError}`) : null; + useEffect(() => { + if (!validationError) return; + const timeout = window.setTimeout(() => setValidationError(null), 3_000); + return () => window.clearTimeout(timeout); + }, [validationError]); + const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); const secret = value.trim(); if (!secret) { + setValue(""); setValidationError("required"); inputRef.current?.focus(); return; @@ -377,82 +386,117 @@ function AuthForm({ }; return ( -
-
-
-

- {t("app.auth.title")} -

-

- {t("app.auth.help")} -

-
-
- -
- { - setValue(e.target.value); - setValidationError(null); - }} - disabled={submitting} - aria-invalid={validationError ? true : undefined} - aria-describedby={ - validationError - ? "webui-auth-help webui-auth-error" - : "webui-auth-help" - } - className="pr-10" - autoFocus - /> - -
- {errorMessage ? ( - - ) : null} -
- -
-
+
+ +

+ {t("app.auth.title")} +

+
+
+
+ { + setValue(e.target.value); + setValidationError(null); + }} + disabled={submitting} + aria-invalid={validationError ? true : undefined} + aria-describedby={validationError ? "webui-auth-error" : undefined} + placeholder={errorMessage ?? undefined} + className={cn( + "h-12 rounded-full border-foreground/15 bg-muted/30 px-4 pr-24 text-base", + validationError && "placeholder:text-[13px] placeholder:text-red-600 dark:placeholder:text-red-400", + )} + autoFocus + /> + + +
+ {errorMessage ? ( + + ) : null} +
+ + {t("app.auth.helpTitle")} + + + )} + > +

{t("app.auth.helpConfig")}

+ + ~/.nanobot/config.json + +

{t("app.auth.helpSecret")}

+ + channels.websocket.tokenIssueSecret + +

+ }} + /> +

+
+ + + ); } diff --git a/webui/src/components/LanguageSwitcher.tsx b/webui/src/components/LanguageSwitcher.tsx index c2d5bfc3c..4a2b8d38e 100644 --- a/webui/src/components/LanguageSwitcher.tsx +++ b/webui/src/components/LanguageSwitcher.tsx @@ -1,17 +1,31 @@ +import { useState } from "react"; import { useTranslation } from "react-i18next"; import { currentLocale, setAppLanguage } from "@/i18n"; import { supportedLocales, type SupportedLocale } from "@/i18n/config"; +import { cn } from "@/lib/utils"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; -export function LanguageSwitcher() { +export function LanguageSwitcher({ className }: { className?: string }) { const { t } = useTranslation(); + const [pointerFocus, setPointerFocus] = useState(false); return (