Add indicator after leaving a room (#981)

* Refactor UserIndicatorModalView to support no progress

* Add room left indicator in HomeScreenViewModel

* Apply PR suggestion
This commit is contained in:
Alfonso Grillo 2023-05-30 12:32:07 +02:00 committed by GitHub
parent 74b36ce870
commit eba0fe5ce3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 7 deletions

View File

@ -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<Double, Never> {
switch loaderType {
case .none, .unknownProgress:
return Empty().eraseToAnyPublisher()
case .some(.progress(let progress)):
return progress.publisher.eraseToAnyPublisher()
}
}
}

View File

@ -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")
}
}
}

View File

@ -91,7 +91,7 @@ final class BugReportScreenCoordinator: CoordinatorProtocol {
type: .modal,
title: label,
persistent: true,
progressPublisher: progressPublisher)
loaderType: .progress(progressPublisher))
)
}

View File

@ -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))
}
}