mirror of
https://github.com/metabolist/metatext.git
synced 2024-12-22 13:37:01 +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 statusSections: AnyPublisher<[[Status]], Error>
|
||||||
public let paginates: Bool
|
public let paginates: Bool
|
||||||
public let contextParentID: String?
|
public let contextParentID: String?
|
||||||
public var title: String?
|
public let title: String?
|
||||||
|
|
||||||
private let filterContext: Filter.Context
|
private let filterContext: Filter.Context
|
||||||
private let mastodonAPIClient: MastodonAPIClient
|
private let mastodonAPIClient: MastodonAPIClient
|
||||||
|
@ -59,7 +59,7 @@ extension StatusListService {
|
||||||
.eraseToAnyPublisher(),
|
.eraseToAnyPublisher(),
|
||||||
paginates: true,
|
paginates: true,
|
||||||
contextParentID: nil,
|
contextParentID: nil,
|
||||||
title: "turn this into a closure or publisher",
|
title: nil,
|
||||||
filterContext: .account,
|
filterContext: .account,
|
||||||
mastodonAPIClient: mastodonAPIClient,
|
mastodonAPIClient: mastodonAPIClient,
|
||||||
contentDatabase: contentDatabase) { maxID, minID in
|
contentDatabase: contentDatabase) { maxID, minID in
|
||||||
|
|
|
@ -57,7 +57,7 @@ class CollectionViewController: UITableViewController {
|
||||||
tableView.cellLayoutMarginsFollowReadableWidth = true
|
tableView.cellLayoutMarginsFollowReadableWidth = true
|
||||||
tableView.tableFooterView = UIView()
|
tableView.tableFooterView = UIView()
|
||||||
|
|
||||||
// navigationItem.title = viewModel.title
|
viewModel.title.sink { [weak self] in self?.navigationItem.title = $0 }.store(in: &cancellables)
|
||||||
|
|
||||||
viewModel.collectionItems
|
viewModel.collectionItems
|
||||||
.sink { [weak self] in self?.update(items: $0) }
|
.sink { [weak self] in self?.update(items: $0) }
|
||||||
|
|
|
@ -41,6 +41,15 @@ public class AccountStatusesViewModel: StatusListViewModel {
|
||||||
override func isPinned(status: Status) -> Bool {
|
override func isPinned(status: Status) -> Bool {
|
||||||
collection == .statuses && items.first?.contains(CollectionItem(id: status.id, kind: .status)) ?? false
|
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 {
|
public extension AccountStatusesViewModel {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import Foundation
|
||||||
|
|
||||||
public protocol CollectionViewModel {
|
public protocol CollectionViewModel {
|
||||||
var collectionItems: AnyPublisher<[[CollectionItem]], Never> { get }
|
var collectionItems: AnyPublisher<[[CollectionItem]], Never> { get }
|
||||||
|
var title: AnyPublisher<String?, Never> { get }
|
||||||
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 navigationEvents: AnyPublisher<NavigationEvent, Never> { get }
|
var navigationEvents: AnyPublisher<NavigationEvent, Never> { get }
|
||||||
|
|
|
@ -38,6 +38,8 @@ public class StatusListViewModel: ObservableObject {
|
||||||
.assign(to: &$items)
|
.assign(to: &$items)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var title: AnyPublisher<String?, Never> { Just(statusListService.title).eraseToAnyPublisher() }
|
||||||
|
|
||||||
public func request(maxID: String? = nil, minID: String? = nil) {
|
public func request(maxID: String? = nil, minID: String? = nil) {
|
||||||
statusListService.request(maxID: maxID, minID: minID)
|
statusListService.request(maxID: maxID, minID: minID)
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
|
@ -94,8 +96,6 @@ extension StatusListViewModel: CollectionViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension StatusListViewModel {
|
public extension StatusListViewModel {
|
||||||
var title: String? { statusListService.title }
|
|
||||||
|
|
||||||
var paginates: Bool { statusListService.paginates }
|
var paginates: Bool { statusListService.paginates }
|
||||||
|
|
||||||
var contextParentID: String? { statusListService.contextParentID }
|
var contextParentID: String? { statusListService.contextParentID }
|
||||||
|
|
Loading…
Reference in a new issue