mirror of
https://github.com/metabolist/metatext.git
synced 2024-12-22 05:26:30 +00:00
Refactoring
This commit is contained in:
parent
b13f4b89a8
commit
ca96821906
5 changed files with 15 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -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 }
|
||||
|
|
Loading…
Reference in a new issue