@@ -12,12 +12,12 @@ struct ConnectionListView: View {
1212 @Environment ( \. horizontalSizeClass) private var sizeClass
1313 @State private var showingAddConnection = false
1414 @State private var editingConnection : DatabaseConnection ?
15- @State private var selectedConnectionId : UUID ?
15+ @SceneStorage ( " selectedConnectionId " ) private var selectedConnectionIdString : String ?
1616 @State private var columnVisibility : NavigationSplitViewVisibility = . automatic
1717 @State private var showingGroupManagement = false
1818 @State private var showingTagManagement = false
19- @State private var filterTagId : UUID ?
20- @State private var groupByGroup = false
19+ @SceneStorage ( " filterTagId " ) private var filterTagIdString : String ?
20+ @AppStorage ( " groupByGroup " ) private var groupByGroup = false
2121 @State private var editMode : EditMode = . inactive
2222 @State private var connectionToDelete : DatabaseConnection ?
2323
@@ -28,6 +28,22 @@ struct ConnectionListView: View {
2828 )
2929 }
3030
31+ private var selectedConnectionId : Binding < UUID ? > {
32+ Binding (
33+ get: { selectedConnectionIdString. flatMap { UUID ( uuidString: $0) } } ,
34+ set: { selectedConnectionIdString = $0? . uuidString }
35+ )
36+ }
37+
38+ private var selectedConnectionUUID : UUID ? {
39+ selectedConnectionIdString. flatMap { UUID ( uuidString: $0) }
40+ }
41+
42+ private var filterTagId : UUID ? {
43+ get { filterTagIdString. flatMap { UUID ( uuidString: $0) } }
44+ set { filterTagIdString = newValue? . uuidString }
45+ }
46+
3147 private var displayedConnections : [ DatabaseConnection ] {
3248 var result = appState. connections
3349 if let filterTagId {
@@ -44,8 +60,8 @@ struct ConnectionListView: View {
4460 }
4561
4662 private var selectedConnection : DatabaseConnection ? {
47- guard let selectedConnectionId else { return nil }
48- return appState. connections. first { $0. id == selectedConnectionId }
63+ guard let id = selectedConnectionUUID else { return nil }
64+ return appState. connections. first { $0. id == id }
4965 }
5066
5167 var body : some View {
@@ -90,7 +106,7 @@ struct ConnectionListView: View {
90106 . onChange ( of: appState. pendingConnectionId) { _, newId in
91107 navigateToPendingConnection ( newId)
92108 }
93- . onChange ( of: filterTagId ) {
109+ . onChange ( of: filterTagIdString ) {
94110 editMode = . inactive
95111 }
96112 . onChange ( of: groupByGroup) {
@@ -201,8 +217,8 @@ struct ConnectionListView: View {
201217 ) {
202218 Button ( String ( localized: " Delete " ) , role: . destructive) {
203219 if let connection = connectionToDelete {
204- if selectedConnectionId == connection. id {
205- selectedConnectionId = nil
220+ if selectedConnectionUUID == connection. id {
221+ selectedConnectionIdString = nil
206222 }
207223 appState. removeConnection ( connection)
208224 }
@@ -339,7 +355,7 @@ struct ConnectionListView: View {
339355 private func navigateToPendingConnection( _ id: UUID ? ) {
340356 guard let id,
341357 appState. connections. contains ( where: { $0. id == id } ) else { return }
342- selectedConnectionId = id
358+ selectedConnectionIdString = id. uuidString
343359 appState. pendingConnectionId = nil
344360 }
345361
0 commit comments