Fixes #734 - Add a "View logs" option to the report a problem screen

Move bug report and log viewer responsibility to a separate flow coordinator. Reuse it as a child coordinator in the authentication, userSessionFlow and settings flow coordinators.
This commit is contained in:
Stefan Ceriu
2024-01-23 10:13:48 +02:00
committed by GitHub
parent dd28261e1f
commit 31286c75fc
38 changed files with 541 additions and 143 deletions
@@ -17,8 +17,9 @@
import Combine
import SwiftUI
enum BugReportScreenCoordinatorResult {
enum BugReportScreenCoordinatorAction {
case cancel
case viewLogs
case finish
}
@@ -37,7 +38,10 @@ final class BugReportScreenCoordinator: CoordinatorProtocol {
private var viewModel: BugReportScreenViewModelProtocol
private var cancellables = Set<AnyCancellable>()
var completion: ((BugReportScreenCoordinatorResult) -> Void)?
private let actionsSubject: PassthroughSubject<BugReportScreenCoordinatorAction, Never> = .init()
var actions: AnyPublisher<BugReportScreenCoordinatorAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(parameters: BugReportScreenCoordinatorParameters) {
self.parameters = parameters
@@ -56,18 +60,21 @@ final class BugReportScreenCoordinator: CoordinatorProtocol {
.actions
.sink { [weak self] action in
guard let self else { return }
MXLog.info("BugReportViewModel did complete with result: \(action).")
switch action {
case .cancel:
self.completion?(.cancel)
actionsSubject.send(.cancel)
case .viewLogs:
actionsSubject.send(.viewLogs)
case let .submitStarted(progressPublisher):
self.startLoading(label: L10n.commonSending, progressPublisher: progressPublisher)
startLoading(label: L10n.commonSending, progressPublisher: progressPublisher)
case .submitFinished:
self.stopLoading()
self.completion?(.finish)
stopLoading()
actionsSubject.send(.finish)
case .submitFailed(let error):
self.stopLoading()
self.showError(label: error.localizedDescription)
stopLoading()
showError(label: error.localizedDescription)
}
}
.store(in: &cancellables)
@@ -19,6 +19,7 @@ import UIKit
enum BugReportScreenViewModelAction {
case cancel
case viewLogs
case submitStarted(progressPublisher: CurrentValuePublisher<Double, Never>)
case submitFinished
case submitFailed(error: Error)
@@ -42,4 +43,5 @@ enum BugReportScreenViewAction {
case submit
case removeScreenshot
case attachScreenshot(UIImage)
case viewLogs
}
@@ -53,6 +53,8 @@ class BugReportScreenViewModel: BugReportScreenViewModelType, BugReportScreenVie
case .cancel:
uploadTask = nil
actionsSubject.send(.cancel)
case .viewLogs:
actionsSubject.send(.viewLogs)
case .submit:
state.shouldDisableInteraction = true
uploadTask = Task { await submitBugReport() }
@@ -68,6 +68,9 @@ struct BugReportScreen: View {
ListRow(label: .plain(title: L10n.screenBugReportIncludeLogs),
kind: .toggle($context.sendingLogsEnabled))
.accessibilityIdentifier(A11yIdentifiers.bugReportScreen.sendLogs)
ListRow(label: .plain(title: L10n.screenBugReportViewLogs),
kind: .navigationLink { context.send(viewAction: .viewLogs) })
.accessibilityIdentifier(A11yIdentifiers.bugReportScreen.sendLogs)
} footer: {
Text(L10n.screenBugReportLogsDescription)
.compoundListSectionFooter()