Do not try to modify datasource directly (IOS-266)

This commit is contained in:
Marcus Kida 2024-05-02 12:01:19 +02:00
parent a59ab43bec
commit 7b5b0dacc7
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
4 changed files with 13 additions and 10 deletions

View File

@ -150,20 +150,15 @@ extension HomeTimelineViewModel {
func loadMore(item: StatusItem, indexPath: IndexPath) async {
guard case let .feedLoader(record) = item else { return }
guard let diffableDataSource = diffableDataSource else { return }
var snapshot = diffableDataSource.snapshot()
guard let status = record.status else { return }
record.isLoadingMore = true
// reconfigure item
snapshot.reconfigureItems([item])
updateSnapshotUsingReloadData(snapshot: snapshot)
await AuthenticationServiceProvider.shared.fetchAccounts(apiService: context.apiService)
// fetch data
let response = try? await context.apiService.homeTimeline(
sinceID: status.id,
maxID: status.id,
authenticationBox: authContext.mastodonAuthenticationBox
)
@ -180,10 +175,8 @@ extension HomeTimelineViewModel {
record.isLoadingMore = false
record.hasMore = false
updateSnapshotUsingReloadData(snapshot: snapshot)
} else {
record.isLoadingMore = false
updateSnapshotUsingReloadData(snapshot: snapshot)
}
}

View File

@ -39,6 +39,10 @@ extension StatusTableViewCell {
case .feed(let feed):
statusView.configure(feed: feed)
self.separatorLine.isHidden = feed.hasMore
feed.$hasMore.sink(receiveValue: { [weak self] hasMore in
self?.separatorLine.isHidden = hasMore
})
.store(in: &disposeBag)
case .status(let status):
statusView.configure(status: status)

View File

@ -18,7 +18,11 @@ public final class MastodonFeed {
}
public let id: String
@Published
public var hasMore: Bool = false
@Published
public var isLoadingMore: Bool = false
public let status: MastodonStatus?

View File

@ -37,8 +37,10 @@ extension TimelineMiddleLoaderTableViewCell {
feed: MastodonFeed,
delegate: TimelineMiddleLoaderTableViewCellDelegate?
) {
self.viewModel.isFetching = feed.isLoadingMore
feed.$isLoadingMore
.assign(to: \.isFetching, on: self.viewModel)
.store(in: &disposeBag)
self.delegate = delegate
}