diff --git a/ElementX/Sources/Other/UserIndicator/UserIndicator.swift b/ElementX/Sources/Other/UserIndicator/UserIndicator.swift index b8a014c34..3561328f9 100644 --- a/ElementX/Sources/Other/UserIndicator/UserIndicator.swift +++ b/ElementX/Sources/Other/UserIndicator/UserIndicator.swift @@ -14,6 +14,7 @@ // limitations under the License. // +import Combine import Foundation enum UserIndicatorType { @@ -30,10 +31,24 @@ struct UserIndicator: Equatable, Identifiable { lhs.persistent == rhs.persistent } + enum LoaderType { + case unknownProgress + case progress(ProgressPublisher) + } + var id: String = UUID().uuidString var type = UserIndicatorType.toast var title: String var iconName: String? var persistent = false - var progressPublisher: ProgressPublisher? + var loaderType: LoaderType? = .unknownProgress + + var progressPublisher: AnyPublisher { + switch loaderType { + case .none, .unknownProgress: + return Empty().eraseToAnyPublisher() + case .some(.progress(let progress)): + return progress.publisher.eraseToAnyPublisher() + } + } } diff --git a/ElementX/Sources/Other/UserIndicator/UserIndicatorModalView.swift b/ElementX/Sources/Other/UserIndicator/UserIndicatorModalView.swift index ee21fde74..a697c7ed3 100644 --- a/ElementX/Sources/Other/UserIndicator/UserIndicatorModalView.swift +++ b/ElementX/Sources/Other/UserIndicator/UserIndicatorModalView.swift @@ -24,10 +24,10 @@ struct UserIndicatorModalView: View { var body: some View { ZStack { VStack(spacing: 12.0) { - if let progressFraction { - ProgressView(value: progressFraction) - } else { + if case .unknownProgress = indicator.loaderType { ProgressView() + } else if case .progress = indicator.loaderType { + ProgressView(value: progressFraction) } HStack { @@ -45,7 +45,7 @@ struct UserIndicatorModalView: View { .background(Color.element.quinaryContent) .clipShape(RoundedCornerShape(radius: 12.0, corners: .allCorners)) .shadow(color: .black.opacity(0.1), radius: 10.0, y: 4.0) - .onReceive(indicator.progressPublisher?.publisher ?? Empty().eraseToAnyPublisher()) { progress in + .onReceive(indicator.progressPublisher) { progress in progressFraction = progress } .transition(.opacity) @@ -68,9 +68,16 @@ struct UserIndicatorModalView_Previews: PreviewProvider { UserIndicatorModalView(indicator: UserIndicator(type: .modal, title: "Successfully logged in", iconName: "checkmark", - progressPublisher: ProgressTracker(initialValue: 0.5)) + loaderType: .progress(ProgressTracker(initialValue: 0.5))) ) .previewDisplayName("Progress Bar") + + UserIndicatorModalView(indicator: UserIndicator(type: .modal, + title: "Successfully logged in", + iconName: "checkmark", + loaderType: .none) + ) + .previewDisplayName("No progress") } } } diff --git a/ElementX/Sources/Screens/BugReportScreen/BugReportScreenCoordinator.swift b/ElementX/Sources/Screens/BugReportScreen/BugReportScreenCoordinator.swift index 51fbe1cc0..99dfbd01e 100644 --- a/ElementX/Sources/Screens/BugReportScreen/BugReportScreenCoordinator.swift +++ b/ElementX/Sources/Screens/BugReportScreen/BugReportScreenCoordinator.swift @@ -91,7 +91,7 @@ final class BugReportScreenCoordinator: CoordinatorProtocol { type: .modal, title: label, persistent: true, - progressPublisher: progressPublisher) + loaderType: .progress(progressPublisher)) ) } diff --git a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift index 7e23fcc38..65b65b7fa 100644 --- a/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift +++ b/ElementX/Sources/Screens/HomeScreen/HomeScreenViewModel.swift @@ -346,6 +346,11 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol case .none, .some(.failure): state.bindings.alertInfo = AlertInfo(id: UUID(), title: L10n.errorUnknown) case .some(.success): + ServiceLocator.shared.userIndicatorController.submitIndicator(UserIndicator(id: UUID().uuidString, + type: .modal, + title: L10n.commonCurrentUserLeftRoom, + iconName: "checkmark", + loaderType: .none)) callback?(.roomLeft(roomIdentifier: roomId)) } }