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:
4 files changed
+38
-18
No files matched your search
@@ -122,6 +122,9 @@ function AppInner({ status, onLogoutComplete }: AppInnerProps) {
|
||||
const [qqList, setQqList] = useState<QQInfo[]>([]);
|
||||
const [processList, setProcessList] = useState<HookProcessInfo[]>([]);
|
||||
const [systemInfo, setSystemInfo] = useState<SystemInfo | null>(null);
|
||||
// Lives at AppInner level so the user's selection survives across page
|
||||
// navigation (ConfigPage gets unmounted when you switch tabs).
|
||||
const [selectedUin, setSelectedUin] = useState<string | null>(null);
|
||||
|
||||
const refreshQqList = useCallback(async () => {
|
||||
try {
|
||||
@@ -171,6 +174,7 @@ function AppInner({ status, onLogoutComplete }: AppInnerProps) {
|
||||
setQqList([]);
|
||||
setProcessList([]);
|
||||
setSystemInfo(null);
|
||||
setSelectedUin(null);
|
||||
onLogoutComplete();
|
||||
}, [api, onLogoutComplete]);
|
||||
|
||||
@@ -188,7 +192,13 @@ function AppInner({ status, onLogoutComplete }: AppInnerProps) {
|
||||
processOps={processOps}
|
||||
/>
|
||||
)}
|
||||
{active === 'config' && <ConfigPage qqList={qqList} />}
|
||||
{active === 'config' && (
|
||||
<ConfigPage
|
||||
qqList={qqList}
|
||||
selectedUin={selectedUin}
|
||||
onSelectedUinChange={setSelectedUin}
|
||||
/>
|
||||
)}
|
||||
{active === 'logs' && <LogsPage />}
|
||||
{active === 'settings' && <SettingsPage onLogout={handleLogout} />}
|
||||
</MainLayout>
|
||||
|
||||
Reference in new issue
Block a user