mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 17:12:45 +02:00
Fix alert presentation
This commit is contained in:
@@ -43,11 +43,8 @@ final class PollHistoryCoordinator: Coordinator, Presentable {
|
||||
|
||||
func start() {
|
||||
MXLog.debug("[PollHistoryCoordinator] did start.")
|
||||
pollHistoryViewModel.completion = { [weak self] result in
|
||||
switch result {
|
||||
case .genericError:
|
||||
self?.showErrorAlert()
|
||||
}
|
||||
pollHistoryViewModel.completion = { _ in
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,15 +52,3 @@ 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 {
|
||||
case genericError
|
||||
|
||||
}
|
||||
|
||||
// MARK: View
|
||||
@@ -34,6 +34,7 @@ enum PollHistoryMode: CaseIterable {
|
||||
|
||||
struct PollHistoryViewBindings {
|
||||
var mode: PollHistoryMode
|
||||
var alertInfo: AlertInfo<Bool>?
|
||||
}
|
||||
|
||||
struct PollHistoryViewState: BindableState {
|
||||
|
||||
@@ -71,7 +71,7 @@ private extension PollHistoryViewModel {
|
||||
break
|
||||
case .failure:
|
||||
polls = polls ?? []
|
||||
self.completion?(.genericError)
|
||||
state.bindings.alertInfo = .init(id: true, title: VectorL10n.pollHistoryFetchingError)
|
||||
}
|
||||
|
||||
updateViewState()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2023 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -104,18 +104,11 @@ final class PollHistoryViewModelTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testAfterFailureCompletionIsCalled() throws {
|
||||
let expectation = expectation(description: #function)
|
||||
|
||||
pollHistoryService.nextBatchPublishers = [MockPollPublisher.failure]
|
||||
viewModel.completion = { event in
|
||||
XCTAssertEqual(event, .genericError)
|
||||
expectation.fulfill()
|
||||
}
|
||||
viewModel.process(viewAction: .viewAppeared)
|
||||
XCTAssertFalse(viewModel.state.isLoading)
|
||||
XCTAssertNotNil(viewModel.state.polls)
|
||||
|
||||
wait(for: [expectation], timeout: 1.0)
|
||||
XCTAssertNotNil(viewModel.state.bindings.alertInfo)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,9 @@ struct PollHistory: View {
|
||||
.onChange(of: viewModel.mode) { _ in
|
||||
viewModel.send(viewAction: .segmentDidChange)
|
||||
}
|
||||
.alert(item: $viewModel.alertInfo) {
|
||||
$0.alert
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
|
||||
Reference in New Issue
Block a user