summaryrefslogtreecommitdiff
path: root/Sora/Views/Post/Grid
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-07-02 04:04:53 -0700
committerFuwn <[email protected]>2025-07-02 04:04:53 -0700
commitdc6695672f85a137c7b98d5b091ec410750e06b2 (patch)
tree8928680102c6fb8af98ab8010409bfd13d1c2815 /Sora/Views/Post/Grid
parentfeat: Development commit (diff)
downloadsora-testing-dc6695672f85a137c7b98d5b091ec410750e06b2.tar.xz
sora-testing-dc6695672f85a137c7b98d5b091ec410750e06b2.zip
feat: Development commit
Diffstat (limited to 'Sora/Views/Post/Grid')
-rw-r--r--Sora/Views/Post/Grid/PostGridView.swift22
1 files changed, 18 insertions, 4 deletions
diff --git a/Sora/Views/Post/Grid/PostGridView.swift b/Sora/Views/Post/Grid/PostGridView.swift
index 9c7e5b6..97604e5 100644
--- a/Sora/Views/Post/Grid/PostGridView.swift
+++ b/Sora/Views/Post/Grid/PostGridView.swift
@@ -11,6 +11,8 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
@State private var isSearchablePresented = false
@State private var cachedSuggestions: [Either<BooruTag, BooruSearchQuery>] = []
@State private var suppressNextSearchSubmit = false
+ @State private var searchTask: Task<Void, Never>?
+ @State private var suggestions: [BooruTag] = []
@Environment(\.isSearching)
private var isSearching
@@ -131,10 +133,22 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
)
}
}
- .onAppear {
+ .onChange(of: manager.searchText) { _, newValue in
if settings.searchSuggestionsMode == .tags {
- cachedSuggestions = manager.allTags.map { tag in
- Either<BooruTag, BooruSearchQuery>.left(tag)
+ searchTask?.cancel()
+
+ searchTask = Task {
+ try? await Task.sleep(nanoseconds: 300_000_000)
+
+ guard !Task.isCancelled else { return }
+
+ let searchTag = newValue.split(separator: " ").last.map(String.init) ?? ""
+
+ if !searchTag.isEmpty {
+ suggestions = await manager.searchTags(name: searchTag)
+ } else {
+ suggestions = []
+ }
}
}
}
@@ -343,7 +357,7 @@ struct PostGridView: View { // swiftlint:disable:this type_body_length
private func searchSuggestionsItems() -> [Either<BooruTag, BooruSearchQuery>] {
switch settings.searchSuggestionsMode {
case .tags:
- return cachedSuggestions
+ return suggestions.map { .left($0) }
case .history:
return settings.searchHistory.map { .right($0) }