fix(app): preserve active host connection choices (#2905)
Settings lost the workspace host when entering the app-wide route, while desktop bootstrap could restore a removed local connection before the saved registry was ready. Use the remembered workspace host for Settings and only register the managed daemon when its server is unknown after registry hydration.
This commit is contained in:
@@ -121,7 +121,10 @@ import {
|
||||
type HostSectionSlug,
|
||||
type SettingsSectionSlug,
|
||||
} from "@/utils/host-routes";
|
||||
import { navigateToLastWorkspace } from "@/stores/navigation-active-workspace-store";
|
||||
import {
|
||||
navigateToLastWorkspace,
|
||||
useLastWorkspaceSelection,
|
||||
} from "@/stores/navigation-active-workspace-store";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// View model
|
||||
@@ -1140,14 +1143,19 @@ export default function SettingsScreen({ view, openAddHostIntent = null }: Setti
|
||||
const hosts = useHosts();
|
||||
const localServerId = useLocalDaemonServerId();
|
||||
const sortedHosts = useSortedHosts(hosts, localServerId);
|
||||
const lastWorkspaceSelection = useLastWorkspaceSelection();
|
||||
const routedSettingsHostServerId =
|
||||
view.kind === "host" || view.kind === "project" ? view.serverId : null;
|
||||
const [selectedSettingsHostServerId, setSelectedSettingsHostServerId] = useState<string | null>(
|
||||
view.kind === "host" || view.kind === "project" ? view.serverId : null,
|
||||
routedSettingsHostServerId ?? lastWorkspaceSelection?.serverId ?? null,
|
||||
);
|
||||
useFocusEffect(
|
||||
useCallback(() => {
|
||||
setSelectedSettingsHostServerId(
|
||||
routedSettingsHostServerId ?? lastWorkspaceSelection?.serverId ?? null,
|
||||
);
|
||||
}, [lastWorkspaceSelection?.serverId, routedSettingsHostServerId]),
|
||||
);
|
||||
useEffect(() => {
|
||||
if (view.kind === "host" || view.kind === "project") {
|
||||
setSelectedSettingsHostServerId(view.serverId);
|
||||
}
|
||||
}, [view]);
|
||||
|
||||
// The host the four sections scope to: the host on the active view, otherwise
|
||||
// the picker choice, otherwise the connected local daemon, otherwise the first host.
|
||||
|
||||
Reference in New Issue
Block a user