mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
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:
@@ -14,6 +14,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import Combine
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
enum UserIndicatorType {
|
enum UserIndicatorType {
|
||||||
@@ -30,10 +31,24 @@ struct UserIndicator: Equatable, Identifiable {
|
|||||||
lhs.persistent == rhs.persistent
|
lhs.persistent == rhs.persistent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum LoaderType {
|
||||||
|
case unknownProgress
|
||||||
|
case progress(ProgressPublisher)
|
||||||
|
}
|
||||||
|
|
||||||
var id: String = UUID().uuidString
|
var id: String = UUID().uuidString
|
||||||
var type = UserIndicatorType.toast
|
var type = UserIndicatorType.toast
|
||||||
var title: String
|
var title: String
|
||||||
var iconName: String?
|
var iconName: String?
|
||||||
var persistent = false
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ struct UserIndicatorModalView: View {
|
|||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
VStack(spacing: 12.0) {
|
VStack(spacing: 12.0) {
|
||||||
if let progressFraction {
|
if case .unknownProgress = indicator.loaderType {
|
||||||
ProgressView(value: progressFraction)
|
|
||||||
} else {
|
|
||||||
ProgressView()
|
ProgressView()
|
||||||
|
} else if case .progress = indicator.loaderType {
|
||||||
|
ProgressView(value: progressFraction)
|
||||||
}
|
}
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
@@ -45,7 +45,7 @@ struct UserIndicatorModalView: View {
|
|||||||
.background(Color.element.quinaryContent)
|
.background(Color.element.quinaryContent)
|
||||||
.clipShape(RoundedCornerShape(radius: 12.0, corners: .allCorners))
|
.clipShape(RoundedCornerShape(radius: 12.0, corners: .allCorners))
|
||||||
.shadow(color: .black.opacity(0.1), radius: 10.0, y: 4.0)
|
.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
|
progressFraction = progress
|
||||||
}
|
}
|
||||||
.transition(.opacity)
|
.transition(.opacity)
|
||||||
@@ -68,9 +68,16 @@ struct UserIndicatorModalView_Previews: PreviewProvider {
|
|||||||
UserIndicatorModalView(indicator: UserIndicator(type: .modal,
|
UserIndicatorModalView(indicator: UserIndicator(type: .modal,
|
||||||
title: "Successfully logged in",
|
title: "Successfully logged in",
|
||||||
iconName: "checkmark",
|
iconName: "checkmark",
|
||||||
progressPublisher: ProgressTracker(initialValue: 0.5))
|
loaderType: .progress(ProgressTracker(initialValue: 0.5)))
|
||||||
)
|
)
|
||||||
.previewDisplayName("Progress Bar")
|
.previewDisplayName("Progress Bar")
|
||||||
|
|
||||||
|
UserIndicatorModalView(indicator: UserIndicator(type: .modal,
|
||||||
|
title: "Successfully logged in",
|
||||||
|
iconName: "checkmark",
|
||||||
|
loaderType: .none)
|
||||||
|
)
|
||||||
|
.previewDisplayName("No progress")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ final class BugReportScreenCoordinator: CoordinatorProtocol {
|
|||||||
type: .modal,
|
type: .modal,
|
||||||
title: label,
|
title: label,
|
||||||
persistent: true,
|
persistent: true,
|
||||||
progressPublisher: progressPublisher)
|
loaderType: .progress(progressPublisher))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -346,6 +346,11 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
|||||||
case .none, .some(.failure):
|
case .none, .some(.failure):
|
||||||
state.bindings.alertInfo = AlertInfo(id: UUID(), title: L10n.errorUnknown)
|
state.bindings.alertInfo = AlertInfo(id: UUID(), title: L10n.errorUnknown)
|
||||||
case .some(.success):
|
case .some(.success):
|
||||||
|
ServiceLocator.shared.userIndicatorController.submitIndicator(UserIndicator(id: UUID().uuidString,
|
||||||
|
type: .modal,
|
||||||
|
title: L10n.commonCurrentUserLeftRoom,
|
||||||
|
iconName: "checkmark",
|
||||||
|
loaderType: .none))
|
||||||
callback?(.roomLeft(roomIdentifier: roomId))
|
callback?(.roomLeft(roomIdentifier: roomId))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user