feat(desktop): preselect the in-use provider on the BYOK page

This commit is contained in:
Saoud Rizwan
2026-10-24 04:41:49 +00:00
parent 3a50dc5e97
commit eca66325b9
@@ -29,12 +29,14 @@ import {
setStoredAppIcon,
} from "@/lib/app-icon";
import { desktopClient } from "@/lib/desktop-client";
import { readModelSelectionStorageFromWindow } from "@/lib/model-selection";
import { resetOnboarding } from "@/lib/onboarding";
import {
getProviderAuthKind,
isProviderConnected,
runProviderOAuthLogin,
} from "@/lib/provider-connection";
import { normalizeProviderId } from "@/lib/provider-id";
import {
invalidateProviderCatalogCache,
notifyVoiceInputSettingsChanged,
@@ -138,6 +140,9 @@ export function SettingsView({
const [selectedProviderId, setSelectedProviderId] = useState<string | null>(
null,
);
const [inUseProviderId] = useState(() =>
normalizeProviderId(readModelSelectionStorageFromWindow().lastProvider),
);
const [addingProvider, setAddingProvider] = useState(false);
// Bumped by every optimistic provider mutation and catalog load. An
// in-flight catalog response is discarded when the generation moved on,
@@ -427,9 +432,13 @@ export function SettingsView({
);
// The detail panel is always open: with no explicit selection, default to
// the first connected provider (the one in use), then the first provider.
// the provider the chat uses, then the first connected one, then the first.
const effectiveSelectedProviderId =
selectedProviderId ??
providers.find(
(provider) =>
provider.id === inUseProviderId && isProviderConnected(provider),
)?.id ??
providers.find(isProviderConnected)?.id ??
providers[0]?.id ??
null;