This commit is contained in:
Justin Mazzocchi 2020-10-05 13:06:50 -07:00
parent 2040c0dc6d
commit 35de31553e
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
4 changed files with 10 additions and 10 deletions

View File

@ -5,7 +5,7 @@ import Foundation
import Mastodon
import ServiceLayer
final public class ListViewModel: ObservableObject {
final public class CollectionItemsViewModel: ObservableObject {
@Published public var alertItem: AlertItem?
public private(set) var nextPageMaxID: String?
public private(set) var maintainScrollPositionOfItem: CollectionItemIdentifier?
@ -33,7 +33,7 @@ final public class ListViewModel: ObservableObject {
}
}
extension ListViewModel: CollectionViewModel {
extension CollectionItemsViewModel: CollectionViewModel {
public var sections: AnyPublisher<[[CollectionItemIdentifier]], Never> {
items.map { $0.map { $0.map(CollectionItemIdentifier.init(item:)) } }.eraseToAnyPublisher()
}
@ -64,7 +64,7 @@ extension ListViewModel: CollectionViewModel {
case let .status(configuration):
navigationEventsSubject.send(
.collectionNavigation(
ListViewModel(
CollectionItemsViewModel(
collectionService: collectionService
.navigationService
.contextService(id: configuration.status.displayStatus.id))))
@ -134,7 +134,7 @@ extension ListViewModel: CollectionViewModel {
}
}
private extension ListViewModel {
private extension CollectionItemsViewModel {
func cache(viewModel: CollectionItemViewModel, forItem item: CollectionItem) {
viewModelCache[item] = (viewModel, viewModel.events.flatMap { $0.compactMap(NavigationEvent.init) }
.assignErrorsToAlertItem(to: \.alertItem, on: self)

View File

@ -21,7 +21,7 @@ extension NavigationEvent {
case let .url(url):
self = .urlNavigation(url)
case let .collection(statusListService):
self = .collectionNavigation(ListViewModel(collectionService: statusListService))
self = .collectionNavigation(CollectionItemsViewModel(collectionService: statusListService))
case let .profile(profileService):
self = .profileNavigation(ProfileViewModel(profileService: profileService))
case .webfingerStart:

View File

@ -90,8 +90,8 @@ public extension NavigationViewModel {
.store(in: &cancellables)
}
func viewModel(timeline: Timeline) -> ListViewModel {
ListViewModel(collectionService: identification.service.service(timeline: timeline))
func viewModel(timeline: Timeline) -> CollectionItemsViewModel {
CollectionItemsViewModel(collectionService: identification.service.service(timeline: timeline))
}
}

View File

@ -11,14 +11,14 @@ final public class ProfileViewModel {
@Published public var alertItem: AlertItem?
private let profileService: ProfileService
private let collectionViewModel: CurrentValueSubject<ListViewModel, Never>
private let collectionViewModel: CurrentValueSubject<CollectionItemsViewModel, Never>
private var cancellables = Set<AnyCancellable>()
init(profileService: ProfileService) {
self.profileService = profileService
collectionViewModel = CurrentValueSubject(
ListViewModel(collectionService: profileService.timelineService(profileCollection: .statuses)))
CollectionItemsViewModel(collectionService: profileService.timelineService(profileCollection: .statuses)))
profileService.accountServicePublisher
.map(AccountViewModel.init(accountService:))
@ -27,7 +27,7 @@ final public class ProfileViewModel {
$collection.dropFirst()
.map(profileService.timelineService(profileCollection:))
.map(ListViewModel.init(collectionService:))
.map(CollectionItemsViewModel.init(collectionService:))
.sink { [weak self] in
guard let self = self else { return }