@@ -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+ @AppStorage ( " lastConnectionId " ) 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+ @AppStorage ( " lastFilterTagId " ) 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,21 @@ 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+ filterTagIdString. flatMap { UUID ( uuidString: $0) }
44+ }
45+
3146 private var displayedConnections : [ DatabaseConnection ] {
3247 var result = appState. connections
3348 if let filterTagId {
@@ -44,8 +59,8 @@ struct ConnectionListView: View {
4459 }
4560
4661 private var selectedConnection : DatabaseConnection ? {
47- guard let selectedConnectionId else { return nil }
48- return appState. connections. first { $0. id == selectedConnectionId }
62+ guard let id = selectedConnectionUUID else { return nil }
63+ return appState. connections. first { $0. id == id }
4964 }
5065
5166 var body : some View {
@@ -90,7 +105,7 @@ struct ConnectionListView: View {
90105 . onChange ( of: appState. pendingConnectionId) { _, newId in
91106 navigateToPendingConnection ( newId)
92107 }
93- . onChange ( of: filterTagId ) {
108+ . onChange ( of: filterTagIdString ) {
94109 editMode = . inactive
95110 }
96111 . onChange ( of: groupByGroup) {
@@ -135,7 +150,7 @@ struct ConnectionListView: View {
135150
136151 @ViewBuilder
137152 private var connectionList : some View {
138- let list = List ( selection: $ selectedConnectionId) {
153+ let list = List ( selection: selectedConnectionId) {
139154 if groupByGroup {
140155 groupedContent
141156 } else {
@@ -201,8 +216,8 @@ struct ConnectionListView: View {
201216 ) {
202217 Button ( String ( localized: " Delete " ) , role: . destructive) {
203218 if let connection = connectionToDelete {
204- if selectedConnectionId == connection. id {
205- selectedConnectionId = nil
219+ if selectedConnectionUUID == connection. id {
220+ selectedConnectionIdString = nil
206221 }
207222 appState. removeConnection ( connection)
208223 }
@@ -222,7 +237,7 @@ struct ConnectionListView: View {
222237 if !appState. tags. isEmpty {
223238 Section ( " Filter by Tag " ) {
224239 Button {
225- filterTagId = nil
240+ filterTagIdString = nil
226241 } label: {
227242 HStack {
228243 Text ( " All " )
@@ -233,7 +248,7 @@ struct ConnectionListView: View {
233248 }
234249 ForEach ( appState. tags) { tag in
235250 Button {
236- filterTagId = tag. id
251+ filterTagIdString = tag. id. uuidString
237252 } label: {
238253 HStack {
239254 Image ( systemName: " circle.fill " )
@@ -339,7 +354,7 @@ struct ConnectionListView: View {
339354 private func navigateToPendingConnection( _ id: UUID ? ) {
340355 guard let id,
341356 appState. connections. contains ( where: { $0. id == id } ) else { return }
342- selectedConnectionId = id
357+ selectedConnectionIdString = id. uuidString
343358 appState. pendingConnectionId = nil
344359 }
345360
0 commit comments