Add alert on error

This commit is contained in:
Alfonso Grillo
2023-01-25 18:40:09 +01:00
parent c1002c3945
commit 7494eb66e5
5 changed files with 24 additions and 11 deletions
@@ -44,7 +44,10 @@ final class PollHistoryCoordinator: Coordinator, Presentable {
func start() {
MXLog.debug("[PollHistoryCoordinator] did start.")
pollHistoryViewModel.completion = { [weak self] result in
self?.completion?()
switch result {
case .genericError:
self?.showErrorAlert()
}
}
}
@@ -52,3 +55,15 @@ final class PollHistoryCoordinator: Coordinator, Presentable {
pollHistoryHostingController
}
}
private extension PollHistoryCoordinator {
func showErrorAlert() {
let alert = UIAlertController(title: VectorL10n.pollHistoryFetchingError,
message: nil,
preferredStyle: .alert)
let cancelAction = UIAlertAction(title: VectorL10n.ok, style: .cancel)
alert.addAction(cancelAction)
pollHistoryHostingController.present(alert, animated: true, completion: nil)
}
}
@@ -22,7 +22,7 @@ enum PollHistoryConstants {
}
enum PollHistoryViewModelResult: Equatable {
#warning("e.g. show poll detail")
case genericError
}
// MARK: View
@@ -70,8 +70,8 @@ private extension PollHistoryViewModel {
switch completion {
case .finished:
break
case .failure(_):
#warning("Handle errors")
case .failure:
self.completion?(.genericError)
}
}
@@ -86,13 +86,6 @@ private extension PollHistoryViewModel {
}
.store(in: &subcriptions)
pollService
.pollErrors
.sink { detail in
#warning("Handle errors")
}
.store(in: &subcriptions)
pollService
.fetchedUpTo
.weakAssign(to: \.state.syncedUpTo, on: self)