Add loading view

This commit is contained in:
Alfonso Grillo
2023-01-20 12:11:12 +01:00
parent 1dd11beba3
commit 729da6d6e3
8 changed files with 93 additions and 11 deletions
@@ -28,7 +28,7 @@ final class PollHistoryViewModel: PollHistoryViewModelType, PollHistoryViewModel
init(mode: PollHistoryMode, pollService: PollHistoryServiceProtocol) {
self.pollService = pollService
super.init(initialViewState: PollHistoryViewState(mode: mode))
super.init(initialViewState: PollHistoryViewState(mode: mode, loadingState: .loading(firstLoad: true)))
}
// MARK: - Public
@@ -37,7 +37,7 @@ final class PollHistoryViewModel: PollHistoryViewModelType, PollHistoryViewModel
switch viewAction {
case .viewAppeared:
setupSubscriptions()
pollService.startFetching()
pollService.next()
case .segmentDidChange:
updatePolls()
}
@@ -62,6 +62,22 @@ private extension PollHistoryViewModel {
#warning("Handle errors")
}
.store(in: &subcriptions)
pollService
.isFetching
.filter { $0 }
.first()
.sink { isFetching in
self.state.loadingState = .loading(firstLoad: true)
}
.store(in: &subcriptions)
pollService
.isFetching
.sink { isFetching in
self.state.loadingState = isFetching ? .loading(firstLoad: false) : .idle
}
.store(in: &subcriptions)
}
func updatePolls() {