Sources: Fix searchbar behavior

Cancelling the search now actually cancels the search.

Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
kingbri 2022-09-05 12:42:01 -04:00 committed by Brian Dashore
parent 52409099d7
commit a9d2604fb3

View file

@ -40,14 +40,13 @@ struct SourcesView: View {
return tempSources
}
@State private var viewTask: Task<Void, Never>? = nil
@State private var checkedForSources = false
@State private var searchText: String = ""
@State private var isEditing = false
@State var filteredUpdatedSources: [SourceJson] = []
@State var filteredAvailableSources: [SourceJson] = []
@State private var viewTask: Task<Void, Never>? = nil
@State private var searchText: String = ""
@State private var filteredUpdatedSources: [SourceJson] = []
@State private var filteredAvailableSources: [SourceJson] = []
var body: some View {
NavView {
@ -128,6 +127,9 @@ struct SourcesView: View {
.navigationSearchBar {
SearchBar("Search", text: $searchText, isEditing: $isEditing)
.showsCancelButton(isEditing)
.onCancel {
searchText = ""
}
}
.onChange(of: searchText) { newValue in
filteredAvailableSources = sourceManager.availableSources.filter { searchText.isEmpty ? true : $0.name.contains(searchText) }