@@ -21,10 +21,14 @@ struct TicketsView: View {
2121 @State private var inProgress = false
2222
2323 var body : some View {
24+ let filteredTickets = searchText == " " ? tickets : tickets. where {
25+ $0. title. contains ( searchText, options: . caseInsensitive) ||
26+ $0. problemDescription. contains ( searchText, options: . caseInsensitive)
27+ }
2428 return ZStack {
2529 VStack {
2630 List {
27- ForEach ( tickets ) { ticket in
31+ ForEach ( filteredTickets ) { ticket in
2832 TicketView ( ticket: ticket)
2933 }
3034 }
@@ -33,6 +37,7 @@ struct TicketsView: View {
3337 VStack {
3438 TextField ( " Ticket title " , text: $title)
3539 TextField ( " Ticket description " , text: $description)
40+ . font ( . caption)
3641 Button ( action: addTicket) {
3742 Text ( " Add Ticket " )
3843 }
@@ -54,16 +59,12 @@ struct TicketsView: View {
5459 private func setSubscriptions( ) {
5560 let subscriptions = realm. subscriptions
5661 if subscriptions. first ( named: product) == nil {
57- print ( " Setting subscription for \( product) " )
5862 inProgress = true
59- subscriptions. write {
63+ subscriptions. write ( ) {
6064 subscriptions. append ( QuerySubscription < Ticket > ( name: product) { ticket in
6165 ticket. product == product
6266 } )
63- }
64- // TODO: This seems to be needed atm (10.22.0) so that the view is refreshed once
65- // the tickets have been found
66- DispatchQueue . main. asyncAfter ( deadline: . now( ) + 0.5 ) {
67+ } onComplete: { _ in
6768 inProgress = false
6869 }
6970 }
0 commit comments