fix(webui): preserve config edits on save and UIN choice across tabs

Two regressions slipped into the ApiClient/ConfigPage refactor:

1. api.config.save() ran the POST response through normalizeOneBotConfig
   and used it to overwrite local state. But POST /api/config/:uin
   returns { success, reloaded, message } — no config body — so the
   normaliser produced an empty config and wiped the user's edits as
   soon as the save succeeded. Honour the "save returns canonical view"
   contract by following the POST with a GET inside the client; the
   round-trip stays hidden behind the seam.

2. selectedUin lived inside useOneBotInstanceConfig, so navigating away
   from ConfigPage unmounted the hook and lost the user's selection.
   Lift selectedUin to AppInner and make the hook externally controlled
   via { selectedUin, onSelectedUinChange }. Clear it on logout.
This commit is contained in:
DrSmoothl committed 2026-05-16 02:22:48 +08:00
1 parent 7cef104f93
commit caf724b25c
4 files changed
+38 -18

No files matched your search

@@ -23,6 +23,8 @@ import { useOneBotInstanceConfig } from '@/hooks/use-onebot-instance-config';
interface ConfigPageProps {
qqList: QQInfo[];
selectedUin: string | null;
onSelectedUinChange: (uin: string | null) => void;
}
function qqAvatarUrl(uin: string) {
@@ -93,9 +95,8 @@ function Section({ title, description, onAdd, children, count }: SectionProps) {
);
}
export function ConfigPage({ qqList }: ConfigPageProps) {
export function ConfigPage({ qqList, selectedUin, onSelectedUinChange }: ConfigPageProps) {
const {
selectedUin,
config,
setConfig,
dirty,
@@ -105,7 +106,7 @@ export function ConfigPage({ qqList }: ConfigPageProps) {
cancelSwitch,
save,
saveStatus,
} = useOneBotInstanceConfig(qqList);
} = useOneBotInstanceConfig(qqList, { selectedUin, onSelectedUinChange });
const [confirmSave, setConfirmSave] = useState(false);
const update = (next: OneBotConfig) => setConfig(next);