diff --git a/new-ui/src/shared/components/LocationCard/context/context.tsx b/new-ui/src/shared/components/LocationCard/context/context.tsx index a88352b48..c7cc59f32 100644 --- a/new-ui/src/shared/components/LocationCard/context/context.tsx +++ b/new-ui/src/shared/components/LocationCard/context/context.tsx @@ -61,6 +61,17 @@ export const LocationCardProvider = ({ location.mfa_method ?? MfaMethod.Totp, ); + // Other location updates must not undo an optimistic connection transition. + // biome-ignore lint/correctness/useExhaustiveDependencies: synchronize only on active state + useEffect(() => { + if (location.active) { + setCurrentView(LocationCardViews.Connected); + } else { + setMfaMethod(location.mfa_method ?? MfaMethod.Totp); + setCurrentView(LocationCardViews.Default); + } + }, [location.active]); + const setView = useCallback( (view: LocationCardViewsValue) => { setPreviousView(currentView); diff --git a/new-ui/src/shared/components/LocationCard/views/ConnectedView/ConnectedView.tsx b/new-ui/src/shared/components/LocationCard/views/ConnectedView/ConnectedView.tsx index 9d2d5ef0f..bfade887e 100644 --- a/new-ui/src/shared/components/LocationCard/views/ConnectedView/ConnectedView.tsx +++ b/new-ui/src/shared/components/LocationCard/views/ConnectedView/ConnectedView.tsx @@ -1,5 +1,3 @@ -import { useEffect } from 'react'; -import { MfaMethod } from '../../../../rust-api/types'; import { ThemeSpacing } from '../../../../types'; import { Divider } from '../../../Divider/Divider'; import { SizedBox } from '../../../SizedBox/SizedBox'; @@ -7,18 +5,9 @@ import { LocationCardConnectButton } from '../../components/LocationCardConnectB import { LocationCardConnectionInfo } from '../../components/LocationCardConnectionInfo/LocationCardConnectionInfo'; import { LocationCardConnectionTiles } from '../../components/LocationCardConnectionTiles/LocationCardConnectionTiles'; import { useLocationCardContext } from '../../context/context'; -import { LocationCardViews } from '../../context/types'; export const ConnectedView = () => { - const { location, setView, setMfaMethod } = useLocationCardContext(); - - // biome-ignore lint/correctness/useExhaustiveDependencies: side-effect - useEffect(() => { - if (!location.active) { - setMfaMethod(location.mfa_method ?? MfaMethod.Totp); - setView(LocationCardViews.Default); - } - }, [location.active]); + const { location } = useLocationCardContext(); return (