Refactoring

This commit is contained in:
Justin Mazzocchi 2020-09-22 18:43:06 -07:00
parent b13f4b89a8
commit ca96821906
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
5 changed files with 15 additions and 5 deletions

View File

@ -10,7 +10,7 @@ public struct StatusListService {
public let statusSections: AnyPublisher<[[Status]], Error>
public let paginates: Bool
public let contextParentID: String?
public var title: String?
public let title: String?
private let filterContext: Filter.Context
private let mastodonAPIClient: MastodonAPIClient
@ -59,7 +59,7 @@ extension StatusListService {
.eraseToAnyPublisher(),
paginates: true,
contextParentID: nil,
title: "turn this into a closure or publisher",
title: nil,
filterContext: .account,
mastodonAPIClient: mastodonAPIClient,
contentDatabase: contentDatabase) { maxID, minID in

View File

@ -57,7 +57,7 @@ class CollectionViewController: UITableViewController {
tableView.cellLayoutMarginsFollowReadableWidth = true
tableView.tableFooterView = UIView()
// navigationItem.title = viewModel.title
viewModel.title.sink { [weak self] in self?.navigationItem.title = $0 }.store(in: &cancellables)
viewModel.collectionItems
.sink { [weak self] in self?.update(items: $0) }

View File

@ -41,6 +41,15 @@ public class AccountStatusesViewModel: StatusListViewModel {
override func isPinned(status: Status) -> Bool {
collection == .statuses && items.first?.contains(CollectionItem(id: status.id, kind: .status)) ?? false
}
public override var title: AnyPublisher<String?, Never> {
$account.map {
guard let acct = $0?.acct else { return nil }
return "@".appending(acct)
}
.eraseToAnyPublisher()
}
}
public extension AccountStatusesViewModel {

View File

@ -5,6 +5,7 @@ import Foundation
public protocol CollectionViewModel {
var collectionItems: AnyPublisher<[[CollectionItem]], Never> { get }
var title: AnyPublisher<String?, Never> { get }
var alertItems: AnyPublisher<AlertItem, Never> { get }
var loading: AnyPublisher<Bool, Never> { get }
var navigationEvents: AnyPublisher<NavigationEvent, Never> { get }

View File

@ -38,6 +38,8 @@ public class StatusListViewModel: ObservableObject {
.assign(to: &$items)
}
public var title: AnyPublisher<String?, Never> { Just(statusListService.title).eraseToAnyPublisher() }
public func request(maxID: String? = nil, minID: String? = nil) {
statusListService.request(maxID: maxID, minID: minID)
.receive(on: DispatchQueue.main)
@ -94,8 +96,6 @@ extension StatusListViewModel: CollectionViewModel {
}
public extension StatusListViewModel {
var title: String? { statusListService.title }
var paginates: Bool { statusListService.paginates }
var contextParentID: String? { statusListService.contextParentID }