mirror of
https://github.com/yattee/yattee.git
synced 2025-10-16 04:18:13 +00:00
Search performance improvements
This commit is contained in:
@@ -8,16 +8,9 @@ struct SearchTextField: View {
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
@EnvironmentObject<SearchModel> private var state
|
||||
|
||||
@Binding var queryText: String
|
||||
@Binding var favoriteItem: FavoriteItem?
|
||||
|
||||
private var queryDebouncer = Debouncer(.milliseconds(800))
|
||||
|
||||
init(
|
||||
queryText: Binding<String>,
|
||||
favoriteItem: Binding<FavoriteItem?>? = nil
|
||||
) {
|
||||
_queryText = queryText
|
||||
init(favoriteItem: Binding<FavoriteItem?>? = nil) {
|
||||
_favoriteItem = favoriteItem ?? .constant(nil)
|
||||
}
|
||||
|
||||
@@ -36,7 +29,7 @@ struct SearchTextField: View {
|
||||
.padding(.horizontal, 8)
|
||||
.opacity(0.8)
|
||||
#endif
|
||||
TextField("Search...", text: $queryText) {
|
||||
TextField("Search...", text: $state.queryText) {
|
||||
state.changeQuery { query in
|
||||
query.query = state.queryText
|
||||
navigation.hideKeyboard()
|
||||
@@ -44,33 +37,25 @@ struct SearchTextField: View {
|
||||
recents.addQuery(state.queryText, navigation: navigation)
|
||||
}
|
||||
.disableAutocorrection(true)
|
||||
.onChange(of: state.suggestionSelection) { newValue in
|
||||
self.queryText = newValue
|
||||
}
|
||||
.onChange(of: queryText) { newValue in
|
||||
queryDebouncer.callback = {
|
||||
DispatchQueue.main.async {
|
||||
state.queryText = newValue
|
||||
}
|
||||
}
|
||||
queryDebouncer.call()
|
||||
}
|
||||
#if os(macOS)
|
||||
.frame(maxWidth: 190)
|
||||
.textFieldStyle(.plain)
|
||||
.frame(maxWidth: 190)
|
||||
.textFieldStyle(.plain)
|
||||
#else
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.padding(.leading)
|
||||
.padding(.trailing, 15)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
.padding(.leading)
|
||||
.padding(.trailing, 15)
|
||||
#endif
|
||||
|
||||
if !self.state.queryText.isEmpty {
|
||||
if let favoriteItem = favoriteItem {
|
||||
#if os(iOS)
|
||||
FavoriteButton(item: favoriteItem)
|
||||
.id(favoriteItem?.id)
|
||||
.id(favoriteItem.id)
|
||||
.labelStyle(.iconOnly)
|
||||
.padding(.trailing)
|
||||
#endif
|
||||
}
|
||||
|
||||
if !state.queryText.isEmpty {
|
||||
clearButton
|
||||
} else {
|
||||
#if os(macOS)
|
||||
@@ -96,7 +81,6 @@ struct SearchTextField: View {
|
||||
|
||||
private var clearButton: some View {
|
||||
Button(action: {
|
||||
queryText = ""
|
||||
self.state.queryText = ""
|
||||
}) {
|
||||
Image(systemName: "xmark.circle.fill")
|
||||
|
Reference in New Issue
Block a user