From 423604b18c3f848f4f4213dd9fe436c17a6c9f40 Mon Sep 17 00:00:00 2001 From: Alfonso Grillo Date: Tue, 26 Sep 2023 14:57:40 +0200 Subject: [PATCH] Add "end poll" confirmation dialog (#1799) * Add poll end confirmation dialog * Fix button role in CreatePollScreenViewModel --- .../Resources/Localizations/en.lproj/Localizable.strings | 2 ++ ElementX/Sources/Generated/Strings.swift | 7 +++++++ .../CreatePollScreen/CreatePollScreenViewModel.swift | 2 +- ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift | 3 +++ .../Sources/Screens/RoomScreen/RoomScreenViewModel.swift | 6 +++++- ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift | 1 + 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ElementX/Resources/Localizations/en.lproj/Localizable.strings b/ElementX/Resources/Localizations/en.lproj/Localizable.strings index b032fa6e8..98194d71c 100644 --- a/ElementX/Resources/Localizations/en.lproj/Localizable.strings +++ b/ElementX/Resources/Localizations/en.lproj/Localizable.strings @@ -70,6 +70,7 @@ "action_take_photo" = "Take photo"; "action_view_source" = "View Source"; "action_yes" = "Yes"; +"action.edit_poll" = "Edit poll"; "common_about" = "About"; "common_acceptable_use_policy" = "Acceptable use policy"; "common_advanced_settings" = "Advanced settings"; @@ -147,6 +148,7 @@ "common_verification_complete" = "Verification complete"; "common_video" = "Video"; "common_waiting" = "Waiting…"; +"common_poll_end_confirmation" = "Are you sure you want to end this poll?"; "common_poll_summary" = "Poll: %1$@"; "crash_detection_dialog_content" = "%1$@ crashed the last time it was used. Would you like to share a crash report with us?"; "dialog_permission_camera" = "In order to let the application use the camera, please grant the permission in the system settings."; diff --git a/ElementX/Sources/Generated/Strings.swift b/ElementX/Sources/Generated/Strings.swift index 11762783d..c5777a1fe 100644 --- a/ElementX/Sources/Generated/Strings.swift +++ b/ElementX/Sources/Generated/Strings.swift @@ -236,6 +236,8 @@ public enum L10n { public static var commonPermalink: String { return L10n.tr("Localizable", "common_permalink") } /// Permission public static var commonPermission: String { return L10n.tr("Localizable", "common_permission") } + /// Are you sure you want to end this poll? + public static var commonPollEndConfirmation: String { return L10n.tr("Localizable", "common_poll_end_confirmation") } /// Poll: %1$@ public static func commonPollSummary(_ p1: Any) -> String { return L10n.tr("Localizable", "common_poll_summary", String(describing: p1)) @@ -1300,6 +1302,11 @@ public enum L10n { public static var testLanguageIdentifier: String { return L10n.tr("Localizable", "test_language_identifier") } /// en public static var testUntranslatedDefaultLanguageIdentifier: String { return L10n.tr("Localizable", "test_untranslated_default_language_identifier") } + + public enum Action { + /// Edit poll + public static var editPoll: String { return L10n.tr("Localizable", "action.edit_poll") } + } } // swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length // swiftlint:enable nesting type_body_length type_name vertical_whitespace_opening_braces diff --git a/ElementX/Sources/Screens/CreatePollScreen/CreatePollScreenViewModel.swift b/ElementX/Sources/Screens/CreatePollScreen/CreatePollScreenViewModel.swift index c6905811e..9ebe5fa9a 100644 --- a/ElementX/Sources/Screens/CreatePollScreen/CreatePollScreenViewModel.swift +++ b/ElementX/Sources/Screens/CreatePollScreen/CreatePollScreenViewModel.swift @@ -43,7 +43,7 @@ class CreatePollScreenViewModel: CreatePollScreenViewModelType, CreatePollScreen state.bindings.alertInfo = .init(id: .init(), title: L10n.screenCreatePollDiscardConfirmationTitle, message: L10n.screenCreatePollDiscardConfirmation, - primaryButton: .init(title: L10n.actionCancel, action: nil), + primaryButton: .init(title: L10n.actionCancel, role: .cancel, action: nil), secondaryButton: .init(title: L10n.actionOk, action: { self.actionsSubject.send(.cancel) })) } else { actionsSubject.send(.cancel) diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift index 5a9992caa..6cb38319e 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenModels.swift @@ -125,6 +125,9 @@ struct RoomScreenViewStateBindings { /// Information describing the currently displayed alert. var alertInfo: AlertInfo? + /// An alert info for confirmation actions (e.g. ending a poll) + var confirmationAlertInfo: AlertInfo? + var debugInfo: TimelineItemDebugInfo? var actionMenuInfo: TimelineItemActionMenuInfo? diff --git a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift index 1db78dd3e..2ab81b5c7 100644 --- a/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/RoomScreen/RoomScreenViewModel.swift @@ -155,7 +155,11 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol case .disableLongPress(let itemID): state.longPressDisabledItemID = itemID case let .endPoll(pollStartID): - endPoll(pollStartID: pollStartID) + state.bindings.confirmationAlertInfo = .init(id: .init(), + title: L10n.actionEndPoll, + message: L10n.commonPollEndConfirmation, + primaryButton: .init(title: L10n.actionCancel, role: .cancel, action: nil), + secondaryButton: .init(title: L10n.actionOk, action: { self.endPoll(pollStartID: pollStartID) })) } } diff --git a/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift b/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift index 12885f5ea..4c1a284bb 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/RoomScreen.swift @@ -54,6 +54,7 @@ struct RoomScreen: View { .toolbarBackground(.visible, for: .navigationBar) // Fix the toolbar's background. .overlay { loadingIndicator } .alert(item: $context.alertInfo) + .alert(item: $context.confirmationAlertInfo) .sheet(item: $context.debugInfo) { TimelineItemDebugView(info: $0) } .sheet(item: $context.actionMenuInfo) { info in context.viewState.timelineItemMenuActionProvider?(info.item.id).map { actions in