fix(ios): keep settings open while removing servers

This commit is contained in:
Theo Browne committed 2026-08-09 20:52:50 -07:00
1 parent bcaa79b6cb
commit 275ce96ba6
4 files changed
+74 -4

No files matched your search

@@ -8,6 +8,7 @@ public final class FeatureRootModel {
public private(set) var details: [String: FeatureThreadDetail] = [:]
public private(set) var isLoading = true
public private(set) var isPerformingAction = false
public private(set) var isManagingConnections = false
public var errorMessage: String?
let client: any FeatureClient
@@ -66,6 +67,7 @@ public final class FeatureRootModel {
}
public func disconnect() async {
isManagingConnections = false
await client.disconnect()
snapshot = FeatureSnapshot(
environments: snapshot.environments,
@@ -74,6 +76,10 @@ public final class FeatureRootModel {
details.removeAll()
}
public func setConnectionManagementPresented(_ isPresented: Bool) {
isManagingConnections = isPresented
}
public func addProject(path: String) async -> Bool {
await perform {
try await client.addProject(path: path)
@@ -45,11 +45,25 @@ public struct FeatureRootView: View {
}
/// Keep the last-known workspace visible through a degraded connection.
/// A deliberate disconnect clears workspace data and returns to onboarding.
/// Connection management also stays mounted while saved servers are being
/// removed, so a disconnected fallback cannot destroy its own Settings sheet.
private var shouldShowWorkspace: Bool {
model.snapshot.connection.state != .disconnected
|| !model.snapshot.projects.isEmpty
|| !model.snapshot.threads.isEmpty
FeatureRootPresentation.showsWorkspace(
snapshot: model.snapshot,
isManagingConnections: model.isManagingConnections
)
}
}
enum FeatureRootPresentation {
static func showsWorkspace(
snapshot: FeatureSnapshot,
isManagingConnections: Bool
) -> Bool {
snapshot.connection.state != .disconnected
|| !snapshot.projects.isEmpty
|| !snapshot.threads.isEmpty
|| (isManagingConnections && !snapshot.environments.isEmpty)
}
}
@@ -81,6 +81,12 @@ public struct SettingsView: View {
}
)
}
.onAppear {
model.setConnectionManagementPresented(true)
}
.onDisappear {
model.setConnectionManagementPresented(false)
}
}
}
@@ -5,6 +5,50 @@ import Testing
@MainActor
@Suite("Feature root model")
struct FeatureRootModelTests {
@Test
func connectionManagementStaysMountedForDisconnectedSavedServers() {
let savedEnvironment = FeatureEnvironment(
id: "offline-demo",
name: "Offline demo",
endpoint: "https://offline.example",
connectionState: .disconnected
)
let snapshot = FeatureSnapshot(
connection: .init(state: .disconnected),
environments: [savedEnvironment]
)
#expect(
FeatureRootPresentation.showsWorkspace(
snapshot: snapshot,
isManagingConnections: true
)
)
#expect(
!FeatureRootPresentation.showsWorkspace(
snapshot: snapshot,
isManagingConnections: false
)
)
#expect(
!FeatureRootPresentation.showsWorkspace(
snapshot: FeatureSnapshot(connection: .init(state: .disconnected)),
isManagingConnections: true
)
)
}
@Test
func disconnectEndsConnectionManagement() async {
let client = FeatureClientStub()
let model = FeatureRootModel(client: client)
model.setConnectionManagementPresented(true)
await model.disconnect()
#expect(!model.isManagingConnections)
}
@Test
func testPairReloadsConnectedSnapshot() async {
let client = FeatureClientStub()