fix(webui): streamline the connection screen
This commit is contained in:
1 parent
08b130cdd1
commit
15976ac559
14 files changed
+308
-127
No files matched your search
+121
-77
@@ -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 (
|
||||
<div className="flex h-full w-full items-center justify-center px-6">
|
||||
<form
|
||||
onSubmit={handleSubmit}
|
||||
className="flex w-full max-w-sm flex-col gap-4"
|
||||
>
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-lg font-semibold text-foreground">
|
||||
{t("app.auth.title")}
|
||||
</h1>
|
||||
<p id="webui-auth-help" className="text-sm text-muted-foreground">
|
||||
{t("app.auth.help")}
|
||||
</p>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<label
|
||||
htmlFor="webui-access-password"
|
||||
className="text-sm font-medium text-foreground"
|
||||
>
|
||||
{t("app.auth.label")}
|
||||
</label>
|
||||
<div className="relative">
|
||||
<Input
|
||||
ref={inputRef}
|
||||
id="webui-access-password"
|
||||
name="webui-access-password"
|
||||
type={passwordVisible ? "text" : "password"}
|
||||
autoComplete="current-password"
|
||||
value={value}
|
||||
onChange={(e) => {
|
||||
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
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={submitting}
|
||||
aria-label={t(
|
||||
passwordVisible ? "app.auth.hidePassword" : "app.auth.showPassword",
|
||||
)}
|
||||
aria-controls="webui-access-password"
|
||||
onClick={() => setPasswordVisible((visible) => !visible)}
|
||||
className="absolute right-1 top-1/2 h-8 w-8 -translate-y-1/2 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
{passwordVisible ? (
|
||||
<EyeOff className="h-4 w-4" strokeWidth={1.75} aria-hidden />
|
||||
) : (
|
||||
<Eye className="h-4 w-4" strokeWidth={1.75} aria-hidden />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
{errorMessage ? (
|
||||
<p id="webui-auth-error" role="alert" className="text-sm text-destructive">
|
||||
{errorMessage}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
<Button
|
||||
type="submit"
|
||||
className="w-full"
|
||||
disabled={submitting}
|
||||
<main className="flex h-full w-full flex-col overflow-y-auto bg-background">
|
||||
<div className="mx-5 mt-5 shrink-0 self-end sm:mx-8">
|
||||
<LanguageSwitcher className="h-8 min-w-0 gap-2 px-3 text-xs" />
|
||||
</div>
|
||||
<div className="flex flex-1 shrink-0 items-center justify-center px-6 pb-20 pt-8">
|
||||
<section
|
||||
aria-labelledby="webui-auth-title"
|
||||
className="w-full max-w-xs"
|
||||
>
|
||||
{t("app.auth.submit")}
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
<div className="text-center">
|
||||
<img
|
||||
src="/brand/nanobot_mark.svg"
|
||||
alt=""
|
||||
width={56}
|
||||
height={56}
|
||||
draggable={false}
|
||||
className="mx-auto mb-5 h-14 w-14 select-none"
|
||||
/>
|
||||
<h1 id="webui-auth-title" className="text-balance text-2xl font-semibold tracking-tight text-foreground sm:text-[1.75rem]">
|
||||
{t("app.auth.title")}
|
||||
</h1>
|
||||
</div>
|
||||
<form onSubmit={handleSubmit} className="mt-8">
|
||||
<div className="relative">
|
||||
<Input
|
||||
ref={inputRef}
|
||||
id="webui-access-password"
|
||||
name="webui-access-password"
|
||||
aria-label={t("app.auth.label")}
|
||||
type={passwordVisible ? "text" : "password"}
|
||||
autoComplete="current-password"
|
||||
value={value}
|
||||
onChange={(e) => {
|
||||
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
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={submitting}
|
||||
aria-label={t(
|
||||
passwordVisible ? "app.auth.hidePassword" : "app.auth.showPassword",
|
||||
)}
|
||||
aria-controls="webui-access-password"
|
||||
onClick={() => setPasswordVisible((visible) => !visible)}
|
||||
className="absolute right-12 top-1/2 h-10 w-10 -translate-y-1/2 rounded-full text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
{passwordVisible ? (
|
||||
<EyeOff className="h-4 w-4" strokeWidth={1.75} aria-hidden />
|
||||
) : (
|
||||
<Eye className="h-4 w-4" strokeWidth={1.75} aria-hidden />
|
||||
)}
|
||||
</Button>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={submitting}
|
||||
aria-label={t("app.auth.submit")}
|
||||
title={t("app.auth.submit")}
|
||||
className="absolute right-1 top-1/2 h-10 w-10 -translate-y-1/2 rounded-full"
|
||||
>
|
||||
<ArrowRight className="h-4 w-4" strokeWidth={1.75} aria-hidden />
|
||||
</Button>
|
||||
</div>
|
||||
{errorMessage ? (
|
||||
<p id="webui-auth-error" role="alert" className="sr-only">
|
||||
{errorMessage}
|
||||
</p>
|
||||
) : null}
|
||||
</form>
|
||||
<Disclosure
|
||||
className="mt-4"
|
||||
summaryClassName="flex min-h-11 items-center justify-center gap-1.5 rounded-compact text-[13px] text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50"
|
||||
contentClassName="rounded-control bg-muted/50 p-4 text-sm leading-6 text-muted-foreground"
|
||||
summary={(
|
||||
<>
|
||||
<span>{t("app.auth.helpTitle")}</span>
|
||||
<ChevronDown className="h-3.5 w-3.5 shrink-0 transition-transform group-data-[state=open]/disclosure:rotate-180 motion-reduce:transition-none" strokeWidth={1.5} aria-hidden />
|
||||
</>
|
||||
)}
|
||||
>
|
||||
<p>{t("app.auth.helpConfig")}</p>
|
||||
<code className="mt-2 block rounded-compact bg-background px-3 py-2 font-mono text-xs text-foreground [overflow-wrap:anywhere]">
|
||||
~/.nanobot/config.json
|
||||
</code>
|
||||
<p className="mt-4">{t("app.auth.helpSecret")}</p>
|
||||
<code className="mt-2 block rounded-compact bg-background px-3 py-2 font-mono text-xs text-foreground [overflow-wrap:anywhere]">
|
||||
channels.websocket.tokenIssueSecret
|
||||
</code>
|
||||
<p className="mt-3">
|
||||
<Trans
|
||||
i18nKey="app.auth.helpFallback"
|
||||
components={{ code: <code className="font-mono text-xs text-foreground [overflow-wrap:anywhere]" /> }}
|
||||
/>
|
||||
</p>
|
||||
</Disclosure>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 (
|
||||
<Select value={currentLocale()} onValueChange={(value) => { void setAppLanguage(value as SupportedLocale); }}>
|
||||
<SelectTrigger className="min-w-40 rounded-full" aria-label={t("sidebar.language.ariaLabel")}>
|
||||
<SelectTrigger
|
||||
className={cn("min-w-40 rounded-full", pointerFocus && "focus-visible:ring-0", className)}
|
||||
aria-label={t("sidebar.language.ariaLabel")}
|
||||
onPointerDown={() => setPointerFocus(true)}
|
||||
onKeyDown={() => setPointerFocus(false)}
|
||||
onBlur={() => setPointerFocus(false)}
|
||||
>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectContent
|
||||
onPointerUpCapture={() => setPointerFocus(true)}
|
||||
onPointerDownOutside={() => setPointerFocus(true)}
|
||||
onKeyDownCapture={() => setPointerFocus(false)}
|
||||
onEscapeKeyDown={() => setPointerFocus(false)}
|
||||
>
|
||||
{supportedLocales.map((option) => (
|
||||
<SelectItem key={option.code} value={option.code}>{option.nativeLabel}</SelectItem>
|
||||
))}
|
||||
|
||||
@@ -21,11 +21,14 @@ export const SelectTrigger = React.forwardRef<
|
||||
));
|
||||
SelectTrigger.displayName = "SelectTrigger";
|
||||
|
||||
export function SelectContent({ children }: { children: React.ReactNode }) {
|
||||
export function SelectContent({ children, ...props }: Pick<
|
||||
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>,
|
||||
"children" | "onPointerUpCapture" | "onPointerDownOutside" | "onKeyDownCapture" | "onEscapeKeyDown"
|
||||
>) {
|
||||
const container = useFloatingPortal();
|
||||
return (
|
||||
<SelectPrimitive.Portal container={container ?? undefined}>
|
||||
<SelectPrimitive.Content position="item-aligned" className={cn("z-50 max-h-[min(24rem,calc(100dvh-2rem))] min-w-[10rem] overflow-hidden rounded-control border border-transparent", floatingSurfaceElevationClassName)}>
|
||||
<SelectPrimitive.Content {...props} position="item-aligned" className={cn("z-50 max-h-[min(24rem,calc(100dvh-2rem))] min-w-[10rem] overflow-hidden rounded-control border border-transparent", floatingSurfaceElevationClassName)}>
|
||||
<SelectPrimitive.ScrollUpButton className="flex h-6 items-center justify-center"><ChevronUp className="h-3.5 w-3.5" /></SelectPrimitive.ScrollUpButton>
|
||||
<SelectPrimitive.Viewport className="p-1">
|
||||
{children}
|
||||
|
||||
@@ -12,12 +12,15 @@
|
||||
"auth": {
|
||||
"title": "Connect to nanobot",
|
||||
"label": "WebUI password",
|
||||
"help": "Find this password at channels.websocket.tokenIssueSecret in the nanobot config, usually ~/.nanobot/config.json. If that value is empty, use channels.websocket.token.",
|
||||
"helpTitle": "Where can I find the password?",
|
||||
"helpConfig": "On the device running nanobot, open the config file, usually at:",
|
||||
"helpSecret": "Copy the value of this field as your password:",
|
||||
"helpFallback": "If that value is empty, use <code>channels.websocket.token</code>.",
|
||||
"showPassword": "Show password",
|
||||
"hidePassword": "Hide password",
|
||||
"submit": "Connect",
|
||||
"required": "Enter the WebUI password.",
|
||||
"invalid": "That WebUI password wasn't accepted. Copy it from the nanobot config and try again."
|
||||
"required": "Enter password",
|
||||
"invalid": "Incorrect password"
|
||||
},
|
||||
"account": {
|
||||
"section": "Account",
|
||||
|
||||
@@ -12,12 +12,15 @@
|
||||
"auth": {
|
||||
"title": "Conectar con nanobot",
|
||||
"label": "Contraseña de WebUI",
|
||||
"help": "Busca esta contraseña en channels.websocket.tokenIssueSecret dentro de la configuración de nanobot, normalmente ~/.nanobot/config.json. Si ese valor está vacío, usa channels.websocket.token.",
|
||||
"helpTitle": "¿Dónde encuentro la contraseña?",
|
||||
"helpConfig": "En el dispositivo que ejecuta nanobot, abre el archivo de configuración, normalmente ubicado en:",
|
||||
"helpSecret": "Copia el valor de este campo como contraseña:",
|
||||
"helpFallback": "Si ese valor está vacío, usa <code>channels.websocket.token</code>.",
|
||||
"showPassword": "Mostrar contraseña",
|
||||
"hidePassword": "Ocultar contraseña",
|
||||
"submit": "Conectar",
|
||||
"required": "Introduce la contraseña de WebUI.",
|
||||
"invalid": "No se aceptó esa contraseña de WebUI. Cópiala de la configuración de nanobot e inténtalo de nuevo."
|
||||
"required": "Introduce la contraseña",
|
||||
"invalid": "Contraseña incorrecta"
|
||||
},
|
||||
"account": {
|
||||
"section": "Cuenta",
|
||||
|
||||
@@ -12,12 +12,15 @@
|
||||
"auth": {
|
||||
"title": "Se connecter à nanobot",
|
||||
"label": "Mot de passe de la WebUI",
|
||||
"help": "Ce mot de passe se trouve dans channels.websocket.tokenIssueSecret dans la configuration de nanobot, généralement ~/.nanobot/config.json. Si cette valeur est vide, utilisez channels.websocket.token.",
|
||||
"helpTitle": "Où trouver le mot de passe ?",
|
||||
"helpConfig": "Sur l’appareil qui exécute nanobot, ouvrez le fichier de configuration, généralement situé ici :",
|
||||
"helpSecret": "Copiez la valeur de ce champ comme mot de passe :",
|
||||
"helpFallback": "Si cette valeur est vide, utilisez <code>channels.websocket.token</code>.",
|
||||
"showPassword": "Afficher le mot de passe",
|
||||
"hidePassword": "Masquer le mot de passe",
|
||||
"submit": "Se connecter",
|
||||
"required": "Saisissez le mot de passe de la WebUI.",
|
||||
"invalid": "Ce mot de passe de la WebUI n’a pas été accepté. Copiez-le depuis la configuration de nanobot et réessayez."
|
||||
"required": "Saisissez le mot de passe",
|
||||
"invalid": "Mot de passe incorrect"
|
||||
},
|
||||
"account": {
|
||||
"section": "Compte",
|
||||
|
||||
@@ -12,12 +12,15 @@
|
||||
"auth": {
|
||||
"title": "Hubungkan ke nanobot",
|
||||
"label": "Kata sandi WebUI",
|
||||
"help": "Temukan kata sandi ini di channels.websocket.tokenIssueSecret dalam konfigurasi nanobot, biasanya ~/.nanobot/config.json. Jika nilainya kosong, gunakan channels.websocket.token.",
|
||||
"helpTitle": "Di mana saya bisa menemukan kata sandi?",
|
||||
"helpConfig": "Pada perangkat yang menjalankan nanobot, buka file konfigurasi, biasanya di:",
|
||||
"helpSecret": "Salin nilai kolom ini sebagai kata sandi:",
|
||||
"helpFallback": "Jika nilainya kosong, gunakan <code>channels.websocket.token</code>.",
|
||||
"showPassword": "Tampilkan kata sandi",
|
||||
"hidePassword": "Sembunyikan kata sandi",
|
||||
"submit": "Hubungkan",
|
||||
"required": "Masukkan kata sandi WebUI.",
|
||||
"invalid": "Kata sandi WebUI tersebut tidak diterima. Salin dari konfigurasi nanobot lalu coba lagi."
|
||||
"required": "Masukkan kata sandi",
|
||||
"invalid": "Kata sandi salah"
|
||||
},
|
||||
"account": {
|
||||
"section": "Akun",
|
||||
|
||||
@@ -12,12 +12,15 @@
|
||||
"auth": {
|
||||
"title": "nanobot に接続",
|
||||
"label": "WebUI パスワード",
|
||||
"help": "このパスワードは nanobot の設定内の channels.websocket.tokenIssueSecret にあります。通常は ~/.nanobot/config.json です。この値が空の場合は channels.websocket.token を使用してください。",
|
||||
"helpTitle": "パスワードはどこにありますか?",
|
||||
"helpConfig": "nanobot を実行しているデバイスで設定ファイルを開きます。通常は次の場所にあります:",
|
||||
"helpSecret": "このフィールドの値をパスワードとしてコピーします:",
|
||||
"helpFallback": "値が空の場合は <code>channels.websocket.token</code> を使用してください。",
|
||||
"showPassword": "パスワードを表示",
|
||||
"hidePassword": "パスワードを隠す",
|
||||
"submit": "接続",
|
||||
"required": "WebUI パスワードを入力してください。",
|
||||
"invalid": "その WebUI パスワードは受け付けられませんでした。nanobot の設定からコピーして、もう一度お試しください。"
|
||||
"required": "パスワードを入力",
|
||||
"invalid": "パスワードが違います"
|
||||
},
|
||||
"account": {
|
||||
"section": "アカウント",
|
||||
|
||||
@@ -12,12 +12,15 @@
|
||||
"auth": {
|
||||
"title": "nanobot에 연결",
|
||||
"label": "WebUI 비밀번호",
|
||||
"help": "이 비밀번호는 nanobot 설정의 channels.websocket.tokenIssueSecret에 있으며, 일반적으로 ~/.nanobot/config.json에 저장됩니다. 이 값이 비어 있으면 channels.websocket.token을 사용하세요.",
|
||||
"helpTitle": "비밀번호는 어디에서 찾나요?",
|
||||
"helpConfig": "nanobot을 실행 중인 기기에서 설정 파일을 여세요. 일반적으로 다음 위치에 있습니다:",
|
||||
"helpSecret": "이 필드의 값을 비밀번호로 복사하세요:",
|
||||
"helpFallback": "값이 비어 있으면 <code>channels.websocket.token</code>을 사용하세요.",
|
||||
"showPassword": "비밀번호 표시",
|
||||
"hidePassword": "비밀번호 숨기기",
|
||||
"submit": "연결",
|
||||
"required": "WebUI 비밀번호를 입력하세요.",
|
||||
"invalid": "해당 WebUI 비밀번호가 허용되지 않았습니다. nanobot 설정에서 복사한 후 다시 시도하세요."
|
||||
"required": "비밀번호를 입력하세요",
|
||||
"invalid": "비밀번호를 확인하세요"
|
||||
},
|
||||
"account": {
|
||||
"section": "계정",
|
||||
|
||||
@@ -12,12 +12,15 @@
|
||||
"auth": {
|
||||
"title": "Conectar ao nanobot",
|
||||
"label": "Senha da WebUI",
|
||||
"help": "Encontre esta senha em channels.websocket.tokenIssueSecret na configuração do nanobot, normalmente em ~/.nanobot/config.json. Se esse valor estiver vazio, use channels.websocket.token.",
|
||||
"helpTitle": "Onde encontro a senha?",
|
||||
"helpConfig": "No dispositivo que executa o nanobot, abra o arquivo de configuração, geralmente em:",
|
||||
"helpSecret": "Copie o valor deste campo como senha:",
|
||||
"helpFallback": "Se esse valor estiver vazio, use <code>channels.websocket.token</code>.",
|
||||
"showPassword": "Mostrar senha",
|
||||
"hidePassword": "Ocultar senha",
|
||||
"submit": "Conectar",
|
||||
"required": "Digite a senha da WebUI.",
|
||||
"invalid": "Essa senha da WebUI não foi aceita. Copie-a da configuração do nanobot e tente novamente."
|
||||
"required": "Digite a senha",
|
||||
"invalid": "Senha incorreta"
|
||||
},
|
||||
"account": {
|
||||
"section": "Conta",
|
||||
|
||||
@@ -12,12 +12,15 @@
|
||||
"auth": {
|
||||
"title": "Kết nối với nanobot",
|
||||
"label": "Mật khẩu WebUI",
|
||||
"help": "Tìm mật khẩu này tại channels.websocket.tokenIssueSecret trong cấu hình nanobot, thường là ~/.nanobot/config.json. Nếu giá trị này trống, hãy dùng channels.websocket.token.",
|
||||
"helpTitle": "Tìm mật khẩu ở đâu?",
|
||||
"helpConfig": "Trên thiết bị đang chạy nanobot, mở tệp cấu hình, thường nằm tại:",
|
||||
"helpSecret": "Sao chép giá trị của trường này làm mật khẩu:",
|
||||
"helpFallback": "Nếu giá trị này trống, hãy dùng <code>channels.websocket.token</code>.",
|
||||
"showPassword": "Hiện mật khẩu",
|
||||
"hidePassword": "Ẩn mật khẩu",
|
||||
"submit": "Kết nối",
|
||||
"required": "Nhập mật khẩu WebUI.",
|
||||
"invalid": "Mật khẩu WebUI đó không được chấp nhận. Hãy sao chép từ cấu hình nanobot rồi thử lại."
|
||||
"required": "Nhập mật khẩu",
|
||||
"invalid": "Mật khẩu không đúng"
|
||||
},
|
||||
"account": {
|
||||
"section": "Tài khoản",
|
||||
|
||||
@@ -12,12 +12,15 @@
|
||||
"auth": {
|
||||
"title": "连接到 nanobot",
|
||||
"label": "WebUI 密码",
|
||||
"help": "请在 nanobot 配置中的 channels.websocket.tokenIssueSecret 查找此密码,配置文件通常位于 ~/.nanobot/config.json。若该值为空,请使用 channels.websocket.token。",
|
||||
"helpTitle": "在哪里找到密码?",
|
||||
"helpConfig": "在运行 nanobot 的设备上打开配置文件,通常位于:",
|
||||
"helpSecret": "复制此字段的值作为密码:",
|
||||
"helpFallback": "若该值为空,请使用 <code>channels.websocket.token</code>。",
|
||||
"showPassword": "显示密码",
|
||||
"hidePassword": "隐藏密码",
|
||||
"submit": "连接",
|
||||
"required": "请输入 WebUI 密码。",
|
||||
"invalid": "该 WebUI 密码未通过验证。请从 nanobot 配置中复制密码后重试。"
|
||||
"required": "请输入密码",
|
||||
"invalid": "密码不正确,请重试"
|
||||
},
|
||||
"account": {
|
||||
"section": "账户",
|
||||
|
||||
@@ -12,12 +12,15 @@
|
||||
"auth": {
|
||||
"title": "連線到 nanobot",
|
||||
"label": "WebUI 密碼",
|
||||
"help": "請在 nanobot 設定中的 channels.websocket.tokenIssueSecret 尋找此密碼,設定檔通常位於 ~/.nanobot/config.json。若該值為空,請使用 channels.websocket.token。",
|
||||
"helpTitle": "在哪裡找到密碼?",
|
||||
"helpConfig": "在執行 nanobot 的裝置上開啟設定檔,通常位於:",
|
||||
"helpSecret": "複製此欄位的值作為密碼:",
|
||||
"helpFallback": "若該值為空,請使用 <code>channels.websocket.token</code>。",
|
||||
"showPassword": "顯示密碼",
|
||||
"hidePassword": "隱藏密碼",
|
||||
"submit": "連線",
|
||||
"required": "請輸入 WebUI 密碼。",
|
||||
"invalid": "該 WebUI 密碼未通過驗證。請從 nanobot 設定中複製密碼後再試一次。"
|
||||
"required": "請輸入密碼",
|
||||
"invalid": "密碼不正確,請重試"
|
||||
},
|
||||
"account": {
|
||||
"section": "帳戶",
|
||||
|
||||
@@ -357,23 +357,75 @@ describe("App layout", () => {
|
||||
expect(await screen.findByRole("heading", { level: 1, name: "Connect to nanobot" }))
|
||||
.toBeInTheDocument();
|
||||
const password = screen.getByLabelText("WebUI password");
|
||||
expect(screen.getByText(/channels\.websocket\.tokenIssueSecret/))
|
||||
.toBeInTheDocument();
|
||||
expect(password).toHaveAccessibleDescription(
|
||||
/If that value is empty, use channels\.websocket\.token\./,
|
||||
);
|
||||
expect(password).not.toHaveAttribute("aria-describedby");
|
||||
expect(password).toHaveAttribute(
|
||||
"autocomplete",
|
||||
"current-password",
|
||||
);
|
||||
expect(password).not.toHaveAttribute("placeholder");
|
||||
expect(screen.queryByText("Authentication required")).not.toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByText(/WebUI password wasn't accepted/),
|
||||
).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
|
||||
expect(connectSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("switches language before connecting while preserving the password draft", async () => {
|
||||
vi.mocked(fetchBootstrap).mockRejectedValueOnce(
|
||||
new Error("bootstrap failed: HTTP 401"),
|
||||
);
|
||||
const user = userEvent.setup();
|
||||
|
||||
render(<App />);
|
||||
|
||||
await user.type(await screen.findByLabelText("WebUI password"), "draft-password");
|
||||
await user.tab({ shift: true });
|
||||
expect(screen.getByRole("combobox", { name: "Change language" })).toHaveFocus();
|
||||
await user.keyboard("{Enter}");
|
||||
await screen.findByRole("listbox");
|
||||
await user.keyboard("{ArrowDown}{Enter}");
|
||||
|
||||
expect(await screen.findByRole("heading", { name: "连接到 nanobot" }))
|
||||
.toBeInTheDocument();
|
||||
expect(screen.getByLabelText("WebUI 密码")).toHaveValue("draft-password");
|
||||
expect(screen.getByRole("button", { name: "连接", exact: true })).toBeEnabled();
|
||||
expect(document.documentElement.lang).toBe("zh-CN");
|
||||
expect(localStorage.getItem("nanobot.locale")).toBe("zh-CN");
|
||||
expect(fetchBootstrap).toHaveBeenCalledTimes(1);
|
||||
expect(connectSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("reveals password setup help with the keyboard without submitting the form", async () => {
|
||||
vi.mocked(fetchBootstrap).mockRejectedValueOnce(
|
||||
new Error("bootstrap failed: HTTP 401"),
|
||||
);
|
||||
const user = userEvent.setup();
|
||||
|
||||
render(<App />);
|
||||
|
||||
const password = await screen.findByLabelText("WebUI password");
|
||||
await user.type(password, "draft-password");
|
||||
await user.tab();
|
||||
await user.tab();
|
||||
await user.tab();
|
||||
const help = screen.getByRole("button", { name: "Where can I find the password?" });
|
||||
expect(help).toHaveFocus();
|
||||
expect(help).toHaveAttribute("aria-expanded", "false");
|
||||
const content = document.getElementById(help.getAttribute("aria-controls")!);
|
||||
expect(content).toHaveAttribute("aria-hidden", "true");
|
||||
|
||||
await user.keyboard("{Enter}");
|
||||
|
||||
expect(help).toHaveAttribute("aria-expanded", "true");
|
||||
expect(content).not.toHaveAttribute("aria-hidden");
|
||||
expect(content).toHaveTextContent("~/.nanobot/config.json");
|
||||
expect(content).toHaveTextContent("channels.websocket.tokenIssueSecret");
|
||||
expect(content).toHaveTextContent("If that value is empty, use channels.websocket.token.");
|
||||
|
||||
await user.keyboard(" ");
|
||||
|
||||
expect(help).toHaveAttribute("aria-expanded", "false");
|
||||
expect(password).toHaveValue("draft-password");
|
||||
expect(fetchBootstrap).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("toggles password visibility without changing the password", async () => {
|
||||
vi.mocked(fetchBootstrap).mockRejectedValueOnce(
|
||||
new Error("bootstrap failed: HTTP 401"),
|
||||
@@ -413,14 +465,19 @@ describe("App layout", () => {
|
||||
fireEvent.click(connect);
|
||||
|
||||
expect(await screen.findByRole("alert")).toHaveTextContent(
|
||||
"Enter the WebUI password.",
|
||||
"Enter password",
|
||||
);
|
||||
expect(password).toHaveAttribute("placeholder", "Enter password");
|
||||
expect(password).toHaveAttribute("aria-invalid", "true");
|
||||
expect(password).toHaveAttribute(
|
||||
"aria-describedby",
|
||||
"webui-auth-help webui-auth-error",
|
||||
"webui-auth-error",
|
||||
);
|
||||
expect(password).toHaveFocus();
|
||||
fireEvent.change(password, { target: { value: " " } });
|
||||
fireEvent.click(connect);
|
||||
expect(password).toHaveValue("");
|
||||
expect(password).toHaveAttribute("placeholder", "Enter password");
|
||||
expect(fetchBootstrap).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
@@ -435,9 +492,7 @@ describe("App layout", () => {
|
||||
|
||||
expect(await screen.findByRole("heading", { level: 1, name: "Connect to nanobot" }))
|
||||
.toBeInTheDocument();
|
||||
expect(
|
||||
screen.queryByText(/WebUI password wasn't accepted/),
|
||||
).not.toBeInTheDocument();
|
||||
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
|
||||
expect(connectSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -454,12 +509,47 @@ describe("App layout", () => {
|
||||
|
||||
const retryPassword = await screen.findByLabelText("WebUI password");
|
||||
expect(await screen.findByRole("alert")).toHaveTextContent(
|
||||
"That WebUI password wasn't accepted. Copy it from the nanobot config and try again.",
|
||||
"Incorrect password",
|
||||
);
|
||||
expect(retryPassword).toHaveAttribute("placeholder", "Incorrect password");
|
||||
expect(retryPassword).toHaveValue("");
|
||||
expect(retryPassword).toHaveAttribute("aria-invalid", "true");
|
||||
expect(retryPassword).toHaveFocus();
|
||||
expect(fetchBootstrap).toHaveBeenLastCalledWith("", "wrong-password");
|
||||
expect(connectSpy).not.toHaveBeenCalled();
|
||||
fireEvent.change(retryPassword, { target: { value: "retry-password" } });
|
||||
expect(retryPassword).not.toHaveAttribute("placeholder");
|
||||
expect(retryPassword).not.toHaveAttribute("aria-invalid");
|
||||
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("clears auth feedback after three seconds without moving focus", async () => {
|
||||
vi.mocked(fetchBootstrap).mockRejectedValue(
|
||||
new Error("bootstrap failed: HTTP 401"),
|
||||
);
|
||||
render(<App />);
|
||||
const password = await screen.findByLabelText("WebUI password");
|
||||
vi.useFakeTimers();
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Connect" }));
|
||||
expect(password).toHaveAttribute("placeholder", "Enter password");
|
||||
act(() => vi.advanceTimersByTime(3_000));
|
||||
expect(password).not.toHaveAttribute("placeholder");
|
||||
expect(password).toHaveFocus();
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.change(password, { target: { value: "wrong-password" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Connect" }));
|
||||
});
|
||||
const retryPassword = screen.getByLabelText("WebUI password");
|
||||
expect(retryPassword).toHaveAttribute("placeholder", "Incorrect password");
|
||||
act(() => vi.advanceTimersByTime(2_999));
|
||||
expect(retryPassword).toHaveAttribute("placeholder", "Incorrect password");
|
||||
act(() => vi.advanceTimersByTime(1));
|
||||
expect(retryPassword).not.toHaveAttribute("placeholder");
|
||||
expect(retryPassword).not.toHaveAttribute("aria-invalid");
|
||||
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
|
||||
expect(retryPassword).toHaveFocus();
|
||||
});
|
||||
|
||||
it("keeps sidebar layout out of the main thread width contract", async () => {
|
||||
|
||||
Reference in new issue
Block a user