mirror of
https://github.com/kean/Pulse.git
synced 2026-05-30 21:07:33 +00:00
Fix an issue with load more not working in search
This commit is contained in:
@@ -60,14 +60,16 @@ struct ConsoleSearchResultsListContentView: View {
|
||||
ForEach(viewModel.results) { result in
|
||||
let isLast = result.id == viewModel.results.last?.id
|
||||
ConsoleSearchResultView(viewModel: result, isSeparatorNeeded: !viewModel.parameters.terms.isEmpty && !isLast)
|
||||
.onAppear {
|
||||
viewModel.didScroll(to: result)
|
||||
}
|
||||
}
|
||||
if !viewModel.isSearching && viewModel.hasMore {
|
||||
#if os(iOS) || os(visionOS)
|
||||
PlainListGroupSeparator()
|
||||
#endif
|
||||
Button(action: viewModel.buttonShowMoreResultsTapped) {
|
||||
Text("Show More Results")
|
||||
}
|
||||
if !viewModel.isSearching && !viewModel.hasMore && !viewModel.results.isEmpty {
|
||||
Text("No more results")
|
||||
.frame(maxWidth: .infinity, minHeight: 24, alignment: .center)
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
.listRowSeparator(.hidden, edges: .bottom)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ final class ConsoleSearchViewModel: ObservableObject, ConsoleSearchOperationDele
|
||||
if parameters.isEmpty {
|
||||
return "Search"
|
||||
} else {
|
||||
return "\(results.count) results"
|
||||
return "\(results.count)\(hasMore ? "+" : "") results"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,7 +253,6 @@ final class ConsoleSearchViewModel: ObservableObject, ConsoleSearchOperationDele
|
||||
|
||||
func searchOperationDidFinish(_ operation: ConsoleSearchOperation, hasMore: Bool) {
|
||||
if operation === self.operation {
|
||||
self.operation = nil
|
||||
isSearching = false
|
||||
if dirtyDate != nil {
|
||||
self.dirtyDate = nil
|
||||
@@ -313,11 +312,6 @@ final class ConsoleSearchViewModel: ObservableObject, ConsoleSearchOperationDele
|
||||
}
|
||||
}
|
||||
|
||||
func buttonShowMoreResultsTapped() {
|
||||
isSearching = true
|
||||
operation?.resume()
|
||||
}
|
||||
|
||||
func buttonShowNewlyAddedSearchResultsTapped() {
|
||||
refreshNow()
|
||||
}
|
||||
@@ -327,6 +321,17 @@ final class ConsoleSearchViewModel: ObservableObject, ConsoleSearchOperationDele
|
||||
updateSearchTokens()
|
||||
}
|
||||
|
||||
func didScroll(to result: ConsoleSearchResultViewModel) {
|
||||
guard results.count > 3 && results[results.endIndex - 2].entity.objectID == result.entity.objectID else {
|
||||
return
|
||||
}
|
||||
guard !isSearching && hasMore else {
|
||||
return
|
||||
}
|
||||
isSearching = true
|
||||
operation?.resume() // Load more
|
||||
}
|
||||
|
||||
// MARK: Suggested Tokens
|
||||
|
||||
private func updateSearchTokens() {
|
||||
|
||||
@@ -21,7 +21,7 @@ final class ConsoleSearchOperation {
|
||||
private var entities: [NSManagedObject]
|
||||
private var objectIDs: [NSManagedObjectID]
|
||||
private var index = 0
|
||||
private var cutoff = 10
|
||||
private var cutoff = 12
|
||||
private let service: ConsoleSearchService
|
||||
private let context: NSManagedObjectContext
|
||||
private let lock: os_unfair_lock_t
|
||||
|
||||
Reference in New Issue
Block a user