Fix search closing when entering new query after opening recent

This commit is contained in:
Arkadiusz Fal 2022-01-20 23:13:10 +01:00
parent df72bf99ba
commit 8ab97ddbaf
3 changed files with 6 additions and 3 deletions

View File

@ -34,8 +34,9 @@ final class RecentsModel: ObservableObject {
} }
} }
func addQuery(_ query: String) { func addQuery(_ query: String, navigation: NavigationModel? = nil) {
if !query.isEmpty { if !query.isEmpty {
navigation?.tabSelection = .search
add(.init(from: query)) add(.init(from: query))
} }
} }

View File

@ -3,6 +3,7 @@ import SwiftUI
struct SearchTextField: View { struct SearchTextField: View {
@Environment(\.navigationStyle) private var navigationStyle @Environment(\.navigationStyle) private var navigationStyle
@EnvironmentObject<NavigationModel> private var navigation
@EnvironmentObject<RecentsModel> private var recents @EnvironmentObject<RecentsModel> private var recents
@EnvironmentObject<SearchModel> private var state @EnvironmentObject<SearchModel> private var state
@ -29,7 +30,7 @@ struct SearchTextField: View {
#endif #endif
TextField("Search...", text: $state.queryText) { TextField("Search...", text: $state.queryText) {
state.changeQuery { query in query.query = state.queryText } state.changeQuery { query in query.query = state.queryText }
recents.addQuery(state.queryText) recents.addQuery(state.queryText, navigation: navigation)
} }
.onChange(of: state.queryText) { _ in .onChange(of: state.queryText) { _ in
if state.query.query.compare(state.queryText, options: .caseInsensitive) == .orderedSame { if state.query.query.compare(state.queryText, options: .caseInsensitive) == .orderedSame {

View File

@ -1,6 +1,7 @@
import SwiftUI import SwiftUI
struct SearchSuggestions: View { struct SearchSuggestions: View {
@EnvironmentObject<NavigationModel> private var navigation
@EnvironmentObject<RecentsModel> private var recents @EnvironmentObject<RecentsModel> private var recents
@EnvironmentObject<SearchModel> private var state @EnvironmentObject<SearchModel> private var state
@ -76,7 +77,7 @@ struct SearchSuggestions: View {
state.fieldIsFocused = false state.fieldIsFocused = false
} }
recents.addQuery(state.queryText) recents.addQuery(state.queryText, navigation: navigation)
} }
private var visibleSuggestions: [String] { private var visibleSuggestions: [String] {