mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Add the same unsaved changes alerts that Android has. (#4803)
* Add an alert to Discard or Save when there are unsaved changes on the RoomDetailsEditScreen. * Add an alert to Discard or Save when there are unsaved changes on the UserDetailsEditScreen. * Add an alert to Discard or Save when there are unsaved changes on the SecurityAndPrivacyScreen. * Update strings.
This commit is contained in:
+3
@@ -18,6 +18,7 @@ struct SecurityAndPrivacyScreenCoordinatorParameters {
|
||||
|
||||
enum SecurityAndPrivacyScreenCoordinatorAction {
|
||||
case displayEditAddressScreen
|
||||
case dismiss
|
||||
}
|
||||
|
||||
final class SecurityAndPrivacyScreenCoordinator: CoordinatorProtocol {
|
||||
@@ -45,6 +46,8 @@ final class SecurityAndPrivacyScreenCoordinator: CoordinatorProtocol {
|
||||
switch action {
|
||||
case .displayEditAddressScreen:
|
||||
actionsSubject.send(.displayEditAddressScreen)
|
||||
case .dismiss:
|
||||
actionsSubject.send(.dismiss)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
@@ -10,6 +10,7 @@ import Foundation
|
||||
|
||||
enum SecurityAndPrivacyScreenViewModelAction {
|
||||
case displayEditAddressScreen
|
||||
case dismiss
|
||||
}
|
||||
|
||||
struct SecurityAndPrivacyScreenViewState: BindableState {
|
||||
@@ -188,9 +189,11 @@ enum SecurityAndPrivacyRoomAccessType: Equatable {
|
||||
|
||||
enum SecurityAndPrivacyAlertType {
|
||||
case enableEncryption
|
||||
case unsavedChanges
|
||||
}
|
||||
|
||||
enum SecurityAndPrivacyScreenViewAction {
|
||||
case cancel
|
||||
case save
|
||||
case tryUpdatingEncryption(Bool)
|
||||
case editAddress
|
||||
|
||||
+22
-7
@@ -62,10 +62,10 @@ class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType,
|
||||
MXLog.info("View model: received view action: \(viewAction)")
|
||||
|
||||
switch viewAction {
|
||||
case .cancel:
|
||||
showUnsavedChangesAlert() // The cancel button is only shown when there are unsaved changes.
|
||||
case .save:
|
||||
Task {
|
||||
await saveDesiredSettings()
|
||||
}
|
||||
Task { await saveDesiredSettings() }
|
||||
case .tryUpdatingEncryption(let updatedValue):
|
||||
if updatedValue {
|
||||
state.bindings.alertInfo = .init(id: .enableEncryption,
|
||||
@@ -168,12 +168,19 @@ class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType,
|
||||
}
|
||||
}
|
||||
|
||||
private func saveDesiredSettings() async {
|
||||
private func showUnsavedChangesAlert() {
|
||||
state.bindings.alertInfo = .init(id: .unsavedChanges,
|
||||
title: L10n.dialogUnsavedChangesTitle,
|
||||
message: L10n.dialogUnsavedChangesDescription,
|
||||
primaryButton: .init(title: L10n.actionSave) { Task { await self.saveDesiredSettings(shouldDismiss: true) } },
|
||||
secondaryButton: .init(title: L10n.actionDiscard, role: .cancel) { self.actionsSubject.send(.dismiss) })
|
||||
}
|
||||
|
||||
private func saveDesiredSettings(shouldDismiss: Bool = false) async {
|
||||
showLoadingIndicator()
|
||||
defer { hideLoadingIndicator() }
|
||||
|
||||
defer {
|
||||
hideLoadingIndicator()
|
||||
}
|
||||
var hasFailures = false
|
||||
|
||||
if state.currentSettings.isEncryptionEnabled != state.bindings.desiredSettings.isEncryptionEnabled {
|
||||
switch await roomProxy.enableEncryption() {
|
||||
@@ -181,6 +188,7 @@ class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType,
|
||||
state.currentSettings.isEncryptionEnabled = state.bindings.desiredSettings.isEncryptionEnabled
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
hasFailures = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,6 +198,7 @@ class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType,
|
||||
state.currentSettings.historyVisibility = state.bindings.desiredSettings.historyVisibility
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
hasFailures = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,6 +214,7 @@ class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType,
|
||||
state.currentSettings.accessType = state.bindings.desiredSettings.accessType
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
hasFailures = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,8 +226,13 @@ class SecurityAndPrivacyScreenViewModel: SecurityAndPrivacyScreenViewModelType,
|
||||
state.currentSettings.isVisibileInRoomDirectory = state.bindings.desiredSettings.isVisibileInRoomDirectory
|
||||
case .failure:
|
||||
userIndicatorController.submitIndicator(.init(title: L10n.errorUnknown))
|
||||
hasFailures = true
|
||||
}
|
||||
}
|
||||
|
||||
if shouldDismiss, !hasFailures {
|
||||
actionsSubject.send(.dismiss)
|
||||
}
|
||||
}
|
||||
|
||||
private func handleSelectedSpaceMembersAccess() {
|
||||
|
||||
@@ -39,6 +39,7 @@ struct SecurityAndPrivacyScreen: View {
|
||||
.compoundList()
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationTitle(L10n.screenSecurityAndPrivacyTitle)
|
||||
.navigationBarBackButtonHidden(!context.viewState.isSaveDisabled)
|
||||
.toolbar { toolbar }
|
||||
.alert(item: $context.alertInfo)
|
||||
}
|
||||
@@ -185,6 +186,14 @@ struct SecurityAndPrivacyScreen: View {
|
||||
|
||||
@ToolbarContentBuilder
|
||||
private var toolbar: some ToolbarContent {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
if !context.viewState.isSaveDisabled {
|
||||
Button(L10n.actionCancel) {
|
||||
context.send(viewAction: .cancel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button(L10n.actionSave) {
|
||||
context.send(viewAction: .save)
|
||||
|
||||
Reference in New Issue
Block a user