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