Search fixes
This commit is contained in:
parent
c50a77ddd0
commit
6427ce803f
|
@ -26,7 +26,7 @@ public struct SearchService {
|
|||
|
||||
return (search.offset == nil ? results : $0.0.appending(results), search.limit)
|
||||
}
|
||||
.flatMap(contentDatabase.publisher(results:limit:)).eraseToAnyPublisher()
|
||||
.map(contentDatabase.publisher(results:limit:)).switchToLatest().eraseToAnyPublisher()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -79,13 +79,10 @@ final class ExploreViewController: UICollectionViewController {
|
|||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
viewModel.searchViewModel.events.sink { [weak self] in
|
||||
if case let .navigation(navigation) = $0,
|
||||
case let .searchScope(scope) = navigation {
|
||||
searchController.searchBar.selectedScopeButtonIndex = scope.rawValue
|
||||
viewModel.searchViewModel.searchScopeChanges.sink { [weak self] in
|
||||
searchController.searchBar.selectedScopeButtonIndex = $0.rawValue
|
||||
self?.updateSearchResults(for: searchController)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ public class CollectionItemsViewModel: ObservableObject {
|
|||
private let eventsSubject = PassthroughSubject<AnyPublisher<CollectionItemEvent, Error>, Never>()
|
||||
private let loadingSubject = PassthroughSubject<Bool, Never>()
|
||||
private let expandAllSubject: CurrentValueSubject<ExpandAllState, Never>
|
||||
private let searchScopeChangesSubject = PassthroughSubject<SearchScope, Never>()
|
||||
private var topVisibleIndexPath = IndexPath(item: 0, section: 0)
|
||||
private let lastReadId = CurrentValueSubject<String?, Never>(nil)
|
||||
private var lastSelectedLoadMore: LoadMore?
|
||||
|
@ -105,6 +106,8 @@ extension CollectionItemsViewModel: CollectionViewModel {
|
|||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
public var searchScopeChanges: AnyPublisher<SearchScope, Never> { searchScopeChangesSubject.eraseToAnyPublisher() }
|
||||
|
||||
public var canRefresh: Bool { collectionService.canRefresh }
|
||||
|
||||
public func request(maxId: String? = nil, minId: String? = nil, search: Search?) {
|
||||
|
@ -154,7 +157,7 @@ extension CollectionItemsViewModel: CollectionViewModel {
|
|||
.navigationService
|
||||
.timelineService(timeline: .tag(tag.name)))))
|
||||
case let .moreResults(moreResults):
|
||||
send(event: .navigation(.searchScope(moreResults.scope)))
|
||||
searchScopeChangesSubject.send(moreResults.scope)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ public protocol CollectionViewModel {
|
|||
var alertItems: AnyPublisher<AlertItem, Never> { get }
|
||||
var loading: AnyPublisher<Bool, Never> { get }
|
||||
var events: AnyPublisher<CollectionItemEvent, Never> { get }
|
||||
var searchScopeChanges: AnyPublisher<SearchScope, Never> { get }
|
||||
var nextPageMaxId: String? { get }
|
||||
var canRefresh: Bool { get }
|
||||
func request(maxId: String?, minId: String?, search: Search?)
|
||||
|
|
|
@ -129,6 +129,10 @@ extension ProfileViewModel: CollectionViewModel {
|
|||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
public var searchScopeChanges: AnyPublisher<SearchScope, Never> {
|
||||
collectionViewModel.flatMap(\.searchScopeChanges).eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
public var nextPageMaxId: String? {
|
||||
collectionViewModel.value.nextPageMaxId
|
||||
}
|
||||
|
|
|
@ -16,8 +16,9 @@ public final class SearchViewModel: CollectionItemsViewModel {
|
|||
|
||||
super.init(collectionService: searchService, identityContext: identityContext)
|
||||
|
||||
$query.removeDuplicates()
|
||||
$query.dropFirst()
|
||||
.debounce(for: .seconds(Self.debounceInterval), scheduler: DispatchQueue.global())
|
||||
.removeDuplicates()
|
||||
.combineLatest($scope.removeDuplicates())
|
||||
.sink { [weak self] in
|
||||
self?.request(
|
||||
|
@ -39,7 +40,7 @@ public final class SearchViewModel: CollectionItemsViewModel {
|
|||
}
|
||||
|
||||
private extension SearchViewModel {
|
||||
static let debounceInterval: TimeInterval = 0.25
|
||||
static let debounceInterval: TimeInterval = 0.5
|
||||
}
|
||||
|
||||
private extension SearchScope {
|
||||
|
|
Loading…
Reference in New Issue