mirror of
https://github.com/metabolist/metatext.git
synced 2025-01-05 03:28:41 +00:00
Fix pinned status issues
This commit is contained in:
parent
098d439722
commit
b1a87f86db
3 changed files with 29 additions and 12 deletions
|
@ -28,6 +28,18 @@ public class AccountStatusesViewModel: StatusListViewModel {
|
||||||
.assign(to: &$accountViewModel)
|
.assign(to: &$accountViewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override var collectionItems: AnyPublisher<[[CollectionItem]], Never> {
|
||||||
|
// The pinned key is added to the info of collection items in the first section
|
||||||
|
// so a diffable data source can potentially render it in both sections
|
||||||
|
super.collectionItems
|
||||||
|
.map {
|
||||||
|
$0.enumerated().map {
|
||||||
|
$0 == 0 ? $1.map { .init(id: $0.id, kind: $0.kind, info: [.pinned: true]) } : $1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.eraseToAnyPublisher()
|
||||||
|
}
|
||||||
|
|
||||||
public override var navigationEvents: AnyPublisher<NavigationEvent, Never> {
|
public override var navigationEvents: AnyPublisher<NavigationEvent, Never> {
|
||||||
$accountViewModel.compactMap { $0 }
|
$accountViewModel.compactMap { $0 }
|
||||||
.flatMap(\.events)
|
.flatMap(\.events)
|
||||||
|
@ -50,10 +62,6 @@ public class AccountStatusesViewModel: StatusListViewModel {
|
||||||
super.request(maxID: maxID, minID: minID)
|
super.request(maxID: maxID, minID: minID)
|
||||||
}
|
}
|
||||||
|
|
||||||
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> {
|
public override var title: AnyPublisher<String?, Never> {
|
||||||
$accountViewModel.map { $0?.accountName }.eraseToAnyPublisher()
|
$accountViewModel.map { $0?.accountName }.eraseToAnyPublisher()
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,13 @@
|
||||||
public struct CollectionItem: Hashable {
|
public struct CollectionItem: Hashable {
|
||||||
public let id: String
|
public let id: String
|
||||||
public let kind: Kind
|
public let kind: Kind
|
||||||
|
public let info: [InfoKey: AnyHashable]
|
||||||
|
|
||||||
|
init(id: String, kind: Kind, info: [InfoKey: AnyHashable]? = nil) {
|
||||||
|
self.id = id
|
||||||
|
self.kind = kind
|
||||||
|
self.info = info ?? [InfoKey: AnyHashable]()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension CollectionItem {
|
public extension CollectionItem {
|
||||||
|
@ -10,4 +17,8 @@ public extension CollectionItem {
|
||||||
case status
|
case status
|
||||||
case account
|
case account
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum InfoKey {
|
||||||
|
case pinned
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,8 @@ public class StatusListViewModel: ObservableObject {
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var collectionItems: AnyPublisher<[[CollectionItem]], Never> { $items.eraseToAnyPublisher() }
|
||||||
|
|
||||||
public var navigationEvents: AnyPublisher<NavigationEvent, Never> { navigationEventsSubject.eraseToAnyPublisher() }
|
public var navigationEvents: AnyPublisher<NavigationEvent, Never> { navigationEventsSubject.eraseToAnyPublisher() }
|
||||||
|
|
||||||
public var title: AnyPublisher<String?, Never> { Just(statusListService.title).eraseToAnyPublisher() }
|
public var title: AnyPublisher<String?, Never> { Just(statusListService.title).eraseToAnyPublisher() }
|
||||||
|
@ -55,13 +57,9 @@ public class StatusListViewModel: ObservableObject {
|
||||||
.sink { _ in }
|
.sink { _ in }
|
||||||
.store(in: &cancellables)
|
.store(in: &cancellables)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isPinned(status: Status) -> Bool { false }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extension StatusListViewModel: CollectionViewModel {
|
extension StatusListViewModel: CollectionViewModel {
|
||||||
public var collectionItems: AnyPublisher<[[CollectionItem]], Never> { $items.eraseToAnyPublisher() }
|
|
||||||
|
|
||||||
public var alertItems: AnyPublisher<AlertItem, Never> { $alertItem.compactMap { $0 }.eraseToAnyPublisher() }
|
public var alertItems: AnyPublisher<AlertItem, Never> { $alertItem.compactMap { $0 }.eraseToAnyPublisher() }
|
||||||
|
|
||||||
public var loading: AnyPublisher<Bool, Never> { loadingSubject.eraseToAnyPublisher() }
|
public var loading: AnyPublisher<Bool, Never> { loadingSubject.eraseToAnyPublisher() }
|
||||||
|
@ -93,7 +91,7 @@ extension StatusListViewModel: CollectionViewModel {
|
||||||
public func viewModel(item: CollectionItem) -> Any? {
|
public func viewModel(item: CollectionItem) -> Any? {
|
||||||
switch item.kind {
|
switch item.kind {
|
||||||
case .status:
|
case .status:
|
||||||
return statusViewModel(id: item.id)
|
return statusViewModel(item: item)
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -111,8 +109,8 @@ private extension StatusListViewModel {
|
||||||
|
|
||||||
var contextParentID: String? { statusListService.contextParentID }
|
var contextParentID: String? { statusListService.contextParentID }
|
||||||
|
|
||||||
func statusViewModel(id: String) -> StatusViewModel? {
|
func statusViewModel(item: CollectionItem) -> StatusViewModel? {
|
||||||
guard let status = statuses[id] else { return nil }
|
guard let status = statuses[item.id] else { return nil }
|
||||||
|
|
||||||
var statusViewModel: StatusViewModel
|
var statusViewModel: StatusViewModel
|
||||||
|
|
||||||
|
@ -136,7 +134,7 @@ private extension StatusListViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
statusViewModel.isContextParent = status.id == statusListService.contextParentID
|
statusViewModel.isContextParent = status.id == statusListService.contextParentID
|
||||||
statusViewModel.isPinned = isPinned(status: status)
|
statusViewModel.isPinned = item.info[.pinned] != nil
|
||||||
statusViewModel.isReplyInContext = isReplyInContext(status: status)
|
statusViewModel.isReplyInContext = isReplyInContext(status: status)
|
||||||
statusViewModel.hasReplyFollowing = hasReplyFollowing(status: status)
|
statusViewModel.hasReplyFollowing = hasReplyFollowing(status: status)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue