Final changes for Room Moderation (#2576)

* Add confirmation that the user would like to discard unsaved changes.

* Update string on permissions screen.

* Fix UI tests and update snapshots.

* Fix integration tests.

* Run periphery for Moderation feature.
This commit is contained in:
Doug
2024-03-15 13:41:23 +00:00
committed by GitHub
parent 668c5188fb
commit 3ba34c0704
29 changed files with 84 additions and 47 deletions
@@ -50,6 +50,7 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
private let analytics: AnalyticsService
private let userIndicatorController: UserIndicatorControllerProtocol
// periphery:ignore - used to avoid deallocation
private var rolesAndPermissionsFlowCoordinator: RoomRolesAndPermissionsFlowCoordinator?
private let stateMachine: StateMachine<State, Event> = .init(state: .initial)
+1 -1
View File
@@ -1215,7 +1215,7 @@ internal enum L10n {
internal static var screenRoomChangePermissionsAdministrators: String { return L10n.tr("Localizable", "screen_room_change_permissions_administrators") }
/// Ban people
internal static var screenRoomChangePermissionsBanPeople: String { return L10n.tr("Localizable", "screen_room_change_permissions_ban_people") }
/// Delete messages
/// Remove messages
internal static var screenRoomChangePermissionsDeleteMessages: String { return L10n.tr("Localizable", "screen_room_change_permissions_delete_messages") }
/// Everyone
internal static var screenRoomChangePermissionsEveryone: String { return L10n.tr("Localizable", "screen_room_change_permissions_everyone") }
@@ -43,6 +43,8 @@ struct RoomChangePermissionsScreenViewStateBindings: BindableState {
}
enum RoomChangePermissionsScreenAlertType {
/// A confirmation that the user would like to discard any unsaved changes.
case discardChanges
/// The generic error message.
case generic
}
@@ -50,6 +52,8 @@ enum RoomChangePermissionsScreenAlertType {
enum RoomChangePermissionsScreenViewAction {
/// Save the permissions.
case save
/// Discard any changes and hide the screen.
case cancel
}
extension RoomChangePermissionsScreenViewState {
@@ -49,6 +49,8 @@ class RoomChangePermissionsScreenViewModel: RoomChangePermissionsScreenViewModel
switch viewAction {
case .save:
Task { await save() }
case .cancel:
confirmDiscardChanges()
}
}
@@ -83,6 +85,14 @@ class RoomChangePermissionsScreenViewModel: RoomChangePermissionsScreenViewModel
}
}
private func confirmDiscardChanges() {
state.bindings.alertInfo = AlertInfo(id: .discardChanges,
title: L10n.screenRoomChangeRoleUnsavedChangesTitle,
message: L10n.screenRoomChangeRoleUnsavedChangesDescription,
primaryButton: .init(title: L10n.actionSave) { Task { await self.save() } },
secondaryButton: .init(title: L10n.actionDiscard, role: .cancel) { self.actionsSubject.send(.complete) })
}
// MARK: Loading indicator
private static let indicatorID = "SavingRoomPermissions"
@@ -35,6 +35,7 @@ struct RoomChangePermissionsScreen: View {
.compoundList()
.navigationTitle(context.viewState.title)
.navigationBarTitleDisplayMode(.inline)
.navigationBarBackButtonHidden(context.viewState.hasChanges)
.toolbar { toolbar }
.alert(item: $context.alertInfo)
}
@@ -47,6 +48,14 @@ struct RoomChangePermissionsScreen: View {
}
.disabled(!context.viewState.hasChanges)
}
if context.viewState.hasChanges {
ToolbarItem(placement: .cancellationAction) {
Button(L10n.actionCancel) {
context.send(viewAction: .cancel)
}
}
}
}
}
@@ -89,6 +89,8 @@ struct RoomChangeRolesScreenViewStateBindings {
enum RoomChangeRolesScreenAlertType {
/// A warning that a particular promotion can't be undone.
case promotionWarning
/// A confirmation that the user would like to discard any unsaved changes.
case discardChanges
/// The generic error message.
case error
}
@@ -100,4 +102,6 @@ enum RoomChangeRolesScreenViewAction {
case demoteMember(RoomMemberDetails)
/// Save all the changes that the user has made.
case save
/// Discard any changes and hide the screen.
case cancel
}
@@ -74,6 +74,8 @@ class RoomChangeRolesScreenViewModel: RoomChangeRolesScreenViewModelType, RoomCh
} else {
Task { await save() }
}
case .cancel:
confirmDiscardChanges()
}
}
@@ -148,6 +150,14 @@ class RoomChangeRolesScreenViewModel: RoomChangeRolesScreenViewModelType, RoomCh
}
}
private func confirmDiscardChanges() {
state.bindings.alertInfo = AlertInfo(id: .discardChanges,
title: L10n.screenRoomChangeRoleUnsavedChangesTitle,
message: L10n.screenRoomChangeRoleUnsavedChangesDescription,
primaryButton: .init(title: L10n.actionSave) { Task { await self.save() } },
secondaryButton: .init(title: L10n.actionDiscard, role: .cancel) { self.actionsSubject.send(.complete) })
}
// MARK: Loading indicator
private static let indicatorID = "SavingRoomRoles"
@@ -61,15 +61,6 @@ struct RoomChangeRolesScreen: View {
}
}
private var noResultsContent: some View {
Text(L10n.commonNoResults)
.font(.compound.bodyLG)
.foregroundColor(.compound.textSecondary)
.frame(maxWidth: .infinity)
.listRowBackground(Color.clear)
.accessibilityIdentifier(A11yIdentifiers.startChatScreen.searchNoResults)
}
@ViewBuilder
private var membersSection: some View {
if !context.viewState.visibleMembers.isEmpty {
@@ -123,6 +114,14 @@ struct RoomChangeRolesScreen: View {
}
.disabled(!context.viewState.hasChanges)
}
if context.viewState.hasChanges {
ToolbarItem(placement: .cancellationAction) {
Button(L10n.actionCancel) {
context.send(viewAction: .cancel)
}
}
}
}
}
@@ -66,7 +66,7 @@ class RoomRolesAndPermissionsScreenViewModel: RoomRolesAndPermissionsScreenViewM
case .editRoles(let role):
actionsSubject.send(.editRoles(role))
case .editOwnUserRole:
state.bindings.alertInfo = AlertInfo(id: .resetConfirmation,
state.bindings.alertInfo = AlertInfo(id: .editOwnRole,
title: L10n.screenRoomRolesAndPermissionsChangeMyRole,
message: L10n.screenRoomChangeRoleConfirmDemoteSelfDescription,
primaryButton: .init(title: L10n.actionCancel, role: .cancel) { },