fix(webui): save settings when editing completes (NAN-323) (#6384)
* fix(webui): save settings when editing completes (NAN-323) * fix(webui): close settings completion and verification gaps * refactor(webui): simplify settings edit ownership
This commit is contained in:
1 parent
26e1f41a00
commit
c6babb20e8
34 files changed
+1363
-388
No files matched your search
+31
-24
@@ -206,6 +206,11 @@ function shellViewForSettingsSection(section: SettingsSectionKey): ShellView {
|
||||
return "settings";
|
||||
}
|
||||
|
||||
function changesSettingsSurface(current: ShellRoute, next: ShellRoute): boolean {
|
||||
return current.view !== "chat" && current.view !== "remote" &&
|
||||
(current.view !== next.view || current.settingsSection !== next.settingsSection);
|
||||
}
|
||||
|
||||
function fallbackRestartHash(hash: string): boolean {
|
||||
return !hash || hash === "/" || hash === "/new";
|
||||
}
|
||||
@@ -1353,33 +1358,36 @@ function Shell({
|
||||
retainedTemporaryChatIdsRef.current = retained;
|
||||
}, [temporaryChatIds, threadMessageCache, filePreviewStore, draftStore]);
|
||||
|
||||
const commitNavigation = useCallback((route: ShellRoute, options?: { replace?: boolean }) => {
|
||||
// The visible sidebar always belongs to its existing host. Navigation
|
||||
// dismisses global management without switching to a different host.
|
||||
if (remoteConnectionsRef.current?.managing) remoteConnectionsRef.current.closeManagement();
|
||||
setActiveKey(route.activeKey);
|
||||
setView(route.view);
|
||||
setSettingsInitialSection(route.settingsSection);
|
||||
writeShellRoute({
|
||||
...route,
|
||||
temporary: route.temporary || Boolean(route.activeKey && temporarySessionsRef.current[route.activeKey]),
|
||||
}, options?.replace);
|
||||
}, []);
|
||||
const navigate = useCallback(
|
||||
(route: ShellRoute, options?: { replace?: boolean }) => {
|
||||
const leave = () => {
|
||||
// The visible sidebar always belongs to its existing host. Navigation
|
||||
// dismisses global management without switching to a different host.
|
||||
if (remoteConnectionsRef.current?.managing) remoteConnectionsRef.current.closeManagement();
|
||||
setActiveKey(route.activeKey);
|
||||
setView(route.view);
|
||||
setSettingsInitialSection(route.settingsSection);
|
||||
writeShellRoute({
|
||||
...route,
|
||||
temporary: route.temporary || Boolean(route.activeKey && temporarySessionsRef.current[route.activeKey]),
|
||||
}, options?.replace);
|
||||
};
|
||||
if (currentShellRouteRef.current.view === "settings" && route.view !== "settings" && settingsExitGuardRef.current) {
|
||||
settingsExitGuardRef.current(leave);
|
||||
const leave = () => commitNavigation(route, options);
|
||||
const current = currentShellRouteRef.current;
|
||||
if (changesSettingsSurface(current, route) && settingsExitGuardRef.current) {
|
||||
settingsExitGuardRef.current(leave, { promptRestart: current.view !== route.view });
|
||||
} else leave();
|
||||
},
|
||||
[],
|
||||
[commitNavigation],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const applyRoute = () => {
|
||||
const route = readShellRoute();
|
||||
if (route.view === "remote") setMobileSidebarOpen(false);
|
||||
if (currentShellRouteRef.current.view === "settings" && route.view !== "settings" && settingsExitGuardRef.current) {
|
||||
writeShellRoute(currentShellRouteRef.current, true);
|
||||
const current = currentShellRouteRef.current;
|
||||
if (changesSettingsSurface(current, route) && settingsExitGuardRef.current) {
|
||||
writeShellRoute(current, true);
|
||||
settingsExitGuardRef.current(() => {
|
||||
setActiveKey(route.activeKey);
|
||||
setView(route.view);
|
||||
@@ -1387,7 +1395,7 @@ function Shell({
|
||||
writeShellRoute(route, true);
|
||||
setWorkspaceError(null);
|
||||
if (route.view === "chat" && !route.activeKey) setDraftWorkspaceScope(null);
|
||||
});
|
||||
}, { promptRestart: current.view !== route.view });
|
||||
return;
|
||||
}
|
||||
setActiveKey(route.activeKey);
|
||||
@@ -2201,13 +2209,12 @@ function Shell({
|
||||
|
||||
const onSettingsSectionChange = useCallback(
|
||||
(section: SettingsSectionKey) => {
|
||||
navigate({
|
||||
view: shellViewForSettingsSection(section),
|
||||
activeKey,
|
||||
settingsSection: section,
|
||||
});
|
||||
const route = { view: shellViewForSettingsSection(section), activeKey, settingsSection: section };
|
||||
// The page has completed or retained its outgoing drafts for in-page transitions.
|
||||
if (currentShellRouteRef.current.view === route.view) commitNavigation(route);
|
||||
else navigate(route);
|
||||
},
|
||||
[activeKey, navigate],
|
||||
[activeKey, commitNavigation, navigate],
|
||||
);
|
||||
|
||||
const onBackToChat = useCallback(() => {
|
||||
|
||||
Reference in new issue
Block a user