Support load more in PollHistoryService

This commit is contained in:
Alfonso Grillo
2023-01-25 12:05:28 +01:00
parent 92fdc406a3
commit ef19527856
4 changed files with 39 additions and 5 deletions
@@ -40,6 +40,8 @@ final class PollHistoryViewModel: PollHistoryViewModelType, PollHistoryViewModel
fetchFirstBatch()
case .segmentDidChange:
updateViewState()
case .loadMoreContent:
fetchMoreContent()
}
}
}
@@ -61,6 +63,21 @@ private extension PollHistoryViewModel {
.store(in: &subcriptions)
}
func fetchMoreContent() {
state.isLoading = true
pollService
.nextBatch()
.sink { [weak self] _ in
#warning("Handle errors")
self?.state.isLoading = false
} receiveValue: { [weak self] poll in
self?.add(poll: poll)
self?.updateViewState()
}
.store(in: &subcriptions)
}
func setupUpdateSubscriptions() {
subcriptions.removeAll()
@@ -88,6 +105,10 @@ private extension PollHistoryViewModel {
polls?[pollIndex] = poll
}
func add(poll: TimelinePollDetails) {
polls?.append(poll)
}
func updateViewState() {
let renderedPolls: [TimelinePollDetails]?