fix(webui): align debug account picker styling (#181)
This commit is contained in:
1 parent
5d6ce86b66
commit
f424454422
2 files changed
+38
-7
No files matched your search
@@ -8,7 +8,6 @@
|
|||||||
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
||||||
import { motion } from 'motion/react';
|
import { motion } from 'motion/react';
|
||||||
import { AlertTriangle, FlaskConical, History, Loader2, Play, RotateCcw, ShieldCheck, Trash2, Zap } from 'lucide-react';
|
import { AlertTriangle, FlaskConical, History, Loader2, Play, RotateCcw, ShieldCheck, Trash2, Zap } from 'lucide-react';
|
||||||
import { Select } from '@/components/ui/select';
|
|
||||||
import { Textarea } from '@/components/ui/textarea';
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
import { Picker } from '@/components/ui/picker';
|
import { Picker } from '@/components/ui/picker';
|
||||||
import { JsonTree } from '@/components/ui/json-tree';
|
import { JsonTree } from '@/components/ui/json-tree';
|
||||||
@@ -27,6 +26,10 @@ const cardCls = 'rounded-2xl border border-border/60 bg-card/80 shadow-[0_1px_2p
|
|||||||
// stakes (the amber banner already warns that any write is real).
|
// stakes (the amber banner already warns that any write is real).
|
||||||
const DESTRUCTIVE_RE = /(kick|ban|mute|recall|withdraw|delete|del_|dismiss|disband|leave|quit|remove|revoke)/i;
|
const DESTRUCTIVE_RE = /(kick|ban|mute|recall|withdraw|delete|del_|dismiss|disband|leave|quit|remove|revoke)/i;
|
||||||
|
|
||||||
|
function qqAvatarUrl(uin: string) {
|
||||||
|
return `/avatar/${encodeURIComponent(uin)}`;
|
||||||
|
}
|
||||||
|
|
||||||
function coerceParam(type: string, raw: string): unknown {
|
function coerceParam(type: string, raw: string): unknown {
|
||||||
if (raw === '') return undefined;
|
if (raw === '') return undefined;
|
||||||
if (/int|uint|number|messageId/i.test(type)) {
|
if (/int|uint|number|messageId/i.test(type)) {
|
||||||
@@ -82,6 +85,18 @@ export function ActionTester({ accounts, docs, presetAction }: { accounts: QQInf
|
|||||||
const isStream = !!doc?.stream;
|
const isStream = !!doc?.stream;
|
||||||
const isDestructive = DESTRUCTIVE_RE.test(actionName);
|
const isDestructive = DESTRUCTIVE_RE.test(actionName);
|
||||||
|
|
||||||
|
const accountOptions = useMemo(
|
||||||
|
() => accounts.length === 0
|
||||||
|
? [{ value: '', label: '(无在线账号)' }]
|
||||||
|
: accounts.map((a) => ({
|
||||||
|
value: a.uin,
|
||||||
|
label: a.nickname || a.uin,
|
||||||
|
sub: a.nickname ? a.uin : undefined,
|
||||||
|
avatar: qqAvatarUrl(a.uin),
|
||||||
|
})),
|
||||||
|
[accounts],
|
||||||
|
);
|
||||||
|
|
||||||
const actionOptions = useMemo(
|
const actionOptions = useMemo(
|
||||||
() => docs.map((d) => ({ value: d.name, label: d.name, sub: d.summary })),
|
() => docs.map((d) => ({ value: d.name, label: d.name, sub: d.summary })),
|
||||||
[docs],
|
[docs],
|
||||||
@@ -201,10 +216,15 @@ export function ActionTester({ accounts, docs, presetAction }: { accounts: QQInf
|
|||||||
|
|
||||||
<div className="grid gap-4 sm:grid-cols-2">
|
<div className="grid gap-4 sm:grid-cols-2">
|
||||||
<Field label="账号">
|
<Field label="账号">
|
||||||
<Select value={uin} onChange={(e) => setUin(e.target.value)}>
|
<Picker
|
||||||
{accounts.length === 0 && <option value="">(无在线账号)</option>}
|
ariaLabel="选择账号"
|
||||||
{accounts.map((a) => <option key={a.uin} value={a.uin}>{a.nickname || a.uin}</option>)}
|
value={uin}
|
||||||
</Select>
|
onChange={setUin}
|
||||||
|
options={accountOptions}
|
||||||
|
placeholder="选择账号…"
|
||||||
|
validateRaw={() => false}
|
||||||
|
disabled={accounts.length === 0}
|
||||||
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
<Field label="Action">
|
<Field label="Action">
|
||||||
<Picker
|
<Picker
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ export function Picker({
|
|||||||
const rootRef = useRef<HTMLDivElement>(null);
|
const rootRef = useRef<HTMLDivElement>(null);
|
||||||
const listRef = useRef<HTMLDivElement>(null);
|
const listRef = useRef<HTMLDivElement>(null);
|
||||||
const searchRef = useRef<HTMLInputElement>(null);
|
const searchRef = useRef<HTMLInputElement>(null);
|
||||||
|
const suppressTriggerClick = useRef(false);
|
||||||
|
|
||||||
const selected = options.find((o) => o.value === value);
|
const selected = options.find((o) => o.value === value);
|
||||||
|
|
||||||
@@ -124,7 +125,13 @@ export function Picker({
|
|||||||
aria-label={ariaLabel}
|
aria-label={ariaLabel}
|
||||||
aria-haspopup="listbox"
|
aria-haspopup="listbox"
|
||||||
aria-expanded={open}
|
aria-expanded={open}
|
||||||
onClick={() => !disabled && setOpen((v) => !v)}
|
onClick={() => {
|
||||||
|
if (suppressTriggerClick.current) {
|
||||||
|
suppressTriggerClick.current = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!disabled) setOpen((v) => !v);
|
||||||
|
}}
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex h-9 w-full items-center gap-2 rounded-md border border-border bg-transparent px-3 text-sm outline-none transition-colors',
|
'flex h-9 w-full items-center gap-2 rounded-md border border-border bg-transparent px-3 text-sm outline-none transition-colors',
|
||||||
'focus-visible:ring-[3px] focus-visible:ring-ring/40 focus-visible:border-ring disabled:opacity-50',
|
'focus-visible:ring-[3px] focus-visible:ring-ring/40 focus-visible:border-ring disabled:opacity-50',
|
||||||
@@ -196,7 +203,11 @@ export function Picker({
|
|||||||
role="option"
|
role="option"
|
||||||
aria-selected={idx === active}
|
aria-selected={idx === active}
|
||||||
onMouseEnter={() => setActive(idx)}
|
onMouseEnter={() => setActive(idx)}
|
||||||
onClick={() => choose(idx)}
|
onPointerDown={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
suppressTriggerClick.current = true;
|
||||||
|
choose(idx);
|
||||||
|
}}
|
||||||
className={cn(
|
className={cn(
|
||||||
'absolute left-0 right-0 flex cursor-pointer items-center gap-2.5 px-3',
|
'absolute left-0 right-0 flex cursor-pointer items-center gap-2.5 px-3',
|
||||||
idx === active ? 'bg-accent text-accent-foreground' : 'hover:bg-accent/50',
|
idx === active ? 'bg-accent text-accent-foreground' : 'hover:bg-accent/50',
|
||||||
|
|||||||
Reference in new issue
Block a user