mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 00:01:00 +00:00
Refactoring
This commit is contained in:
parent
2f888e1968
commit
4c6e242215
7 changed files with 22 additions and 19 deletions
|
@ -34,6 +34,7 @@ extension ContextItemsInfo {
|
|||
&& section[index + 1].record.inReplyToId == statusInfo.record.id
|
||||
|
||||
return .status(.init(status: .init(info: statusInfo),
|
||||
isContextParent: statusInfo.record.id == parent.record.id,
|
||||
isReplyInContext: isReplyInContext,
|
||||
hasReplyFollowing: hasReplyFollowing))
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ extension TimelineItemsInfo {
|
|||
|
||||
if let pinnedStatusInfos = pinnedStatusesInfo?.pinnedStatusInfos {
|
||||
return [pinnedStatusInfos.filtered(regularExpression: filterRegularExpression)
|
||||
.map { CollectionItem.status(.init(status: .init(info: $0), pinned: true)) },
|
||||
.map { CollectionItem.status(.init(status: .init(info: $0), isPinned: true)) },
|
||||
timelineItems]
|
||||
} else {
|
||||
return [timelineItems]
|
||||
|
|
|
@ -11,13 +11,19 @@ public enum CollectionItem: Hashable {
|
|||
public extension CollectionItem {
|
||||
struct StatusConfiguration: Hashable {
|
||||
public let status: Status
|
||||
public let pinned: Bool
|
||||
public let isContextParent: Bool
|
||||
public let isPinned: Bool
|
||||
public let isReplyInContext: Bool
|
||||
public let hasReplyFollowing: Bool
|
||||
|
||||
init(status: Status, pinned: Bool = false, isReplyInContext: Bool = false, hasReplyFollowing: Bool = false) {
|
||||
init(status: Status,
|
||||
isContextParent: Bool = false,
|
||||
isPinned: Bool = false,
|
||||
isReplyInContext: Bool = false,
|
||||
hasReplyFollowing: Bool = false) {
|
||||
self.status = status
|
||||
self.pinned = pinned
|
||||
self.isContextParent = isContextParent
|
||||
self.isPinned = isPinned
|
||||
self.isReplyInContext = isReplyInContext
|
||||
self.hasReplyFollowing = hasReplyFollowing
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ public protocol CollectionService {
|
|||
var nextPageMaxId: AnyPublisher<String, Never> { get }
|
||||
var title: AnyPublisher<String, Never> { get }
|
||||
var navigationService: NavigationService { get }
|
||||
var contextParentId: String? { get }
|
||||
func request(maxId: String?, minId: String?) -> AnyPublisher<Never, Error>
|
||||
}
|
||||
|
||||
|
@ -15,6 +14,4 @@ extension CollectionService {
|
|||
public var nextPageMaxId: AnyPublisher<String, Never> { Empty().eraseToAnyPublisher() }
|
||||
|
||||
public var title: AnyPublisher<String, Never> { Empty().eraseToAnyPublisher() }
|
||||
|
||||
public var contextParentId: String? { nil }
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import MastodonAPI
|
|||
public struct ContextService {
|
||||
public let sections: AnyPublisher<[[CollectionItem]], Error>
|
||||
public let navigationService: NavigationService
|
||||
public var contextParentId: String? { id }
|
||||
|
||||
private let id: Status.Id
|
||||
private let mastodonAPIClient: MastodonAPIClient
|
||||
|
|
|
@ -81,7 +81,7 @@ extension CollectionItemsViewModel: CollectionViewModel {
|
|||
public func canSelect(indexPath: IndexPath) -> Bool {
|
||||
switch items.value[indexPath.section][indexPath.item] {
|
||||
case let .status(configuration):
|
||||
return configuration.status.id != collectionService.contextParentId
|
||||
return !configuration.isContextParent
|
||||
case .loadMore:
|
||||
return !((viewModel(indexPath: indexPath) as? LoadMoreViewModel)?.loading ?? false)
|
||||
default:
|
||||
|
@ -104,8 +104,8 @@ extension CollectionItemsViewModel: CollectionViewModel {
|
|||
cache(viewModel: viewModel, forItem: item)
|
||||
}
|
||||
|
||||
viewModel.isContextParent = configuration.status.id == collectionService.contextParentId
|
||||
viewModel.isPinned = configuration.pinned
|
||||
viewModel.isContextParent = configuration.isContextParent
|
||||
viewModel.isPinned = configuration.isPinned
|
||||
viewModel.isReplyInContext = configuration.isReplyInContext
|
||||
viewModel.hasReplyFollowing = configuration.hasReplyFollowing
|
||||
|
||||
|
@ -156,14 +156,14 @@ private extension CollectionItemsViewModel {
|
|||
maintainScrollPositionOfItem = nil // clear old value
|
||||
|
||||
// Maintain scroll position of parent after initial load of context
|
||||
if let contextParentId = collectionService.contextParentId {
|
||||
let contextParentIdentifier = CollectionItemIdentifier(id: contextParentId, kind: .status, info: [:])
|
||||
let onlyContextParentId = [[], [contextParentIdentifier], []]
|
||||
if collectionService is ContextService,
|
||||
items.value.isEmpty || items.value.map(\.count) == [0, 1, 0],
|
||||
let contextParent = newItems.reduce([], +).first(where: {
|
||||
guard case let .status(configuration) = $0 else { return false }
|
||||
|
||||
if items.value.isEmpty
|
||||
|| items.value.map({ $0.map(CollectionItemIdentifier.init(item:)) }) == onlyContextParentId {
|
||||
maintainScrollPositionOfItem = contextParentIdentifier
|
||||
}
|
||||
return configuration.isContextParent
|
||||
}) {
|
||||
maintainScrollPositionOfItem = .init(item: contextParent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ extension CollectionItemIdentifier {
|
|||
case let .status(configuration):
|
||||
id = configuration.status.id
|
||||
kind = .status
|
||||
info = configuration.pinned ? [.pinned: true] : [:]
|
||||
info = configuration.isPinned ? [.pinned: true] : [:]
|
||||
case let .loadMore(loadMore):
|
||||
id = loadMore.afterStatusId
|
||||
kind = .loadMore
|
||||
|
|
Loading…
Reference in a new issue