mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-14 12:31:00 +00:00
Improve search
This commit is contained in:
parent
b148930801
commit
27213a78f4
4 changed files with 14 additions and 1 deletions
|
@ -24,6 +24,7 @@ public class CollectionItemsViewModel: ObservableObject {
|
|||
private var localLastReadId: CollectionItem.Id?
|
||||
private var markerLastReadId: CollectionItem.Id?
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
private var requestCancellables = Set<AnyCancellable>()
|
||||
|
||||
// swiftlint:disable:next function_body_length
|
||||
public init(collectionService: CollectionService, identityContext: IdentityContext) {
|
||||
|
@ -247,13 +248,19 @@ extension CollectionItemsViewModel: CollectionViewModel {
|
|||
receiveSubscription: { [weak self] _ in self?.loadingSubject.send(true) },
|
||||
receiveCompletion: { [weak self] _ in self?.loadingSubject.send(false) })
|
||||
.sink { _ in }
|
||||
.store(in: &cancellables)
|
||||
.store(in: &requestCancellables)
|
||||
collectionService.requestMarkerLastReadId()
|
||||
.sink { _ in } receiveValue: { [weak self] in self?.markerLastReadId = $0 }
|
||||
.store(in: &cancellables)
|
||||
|
||||
}
|
||||
|
||||
public func cancelRequests() {
|
||||
for cancellable in requestCancellables {
|
||||
cancellable.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
public func select(indexPath: IndexPath) {
|
||||
let item = lastUpdate.sections[indexPath.section].items[indexPath.item]
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ public protocol CollectionViewModel {
|
|||
var announcesNewItems: Bool { get }
|
||||
func request(maxId: String?, minId: String?, search: Search?)
|
||||
func requestNextPage(fromIndexPath indexPath: IndexPath)
|
||||
func cancelRequests()
|
||||
func viewedAtTop(indexPath: IndexPath)
|
||||
func select(indexPath: IndexPath)
|
||||
func canSelect(indexPath: IndexPath) -> Bool
|
||||
|
|
|
@ -158,6 +158,10 @@ extension ProfileViewModel: CollectionViewModel {
|
|||
collectionViewModel.value.request(maxId: maxId, minId: minId, search: nil)
|
||||
}
|
||||
|
||||
public func cancelRequests() {
|
||||
collectionViewModel.value.cancelRequests()
|
||||
}
|
||||
|
||||
public func requestNextPage(fromIndexPath indexPath: IndexPath) {
|
||||
collectionViewModel.value.requestNextPage(fromIndexPath: indexPath)
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ public final class SearchViewModel: CollectionItemsViewModel {
|
|||
.removeDuplicates()
|
||||
.combineLatest($scope.removeDuplicates())
|
||||
.sink { [weak self] in
|
||||
self?.cancelRequests()
|
||||
self?.request(
|
||||
maxId: nil,
|
||||
minId: nil,
|
||||
|
|
Loading…
Reference in a new issue