Add a link to the global settings in the room notifications settings (#1433)

This commit is contained in:
Nicolas Mauri
2023-08-02 18:30:05 +02:00
committed by GitHub
parent 6e5854abf9
commit 17aa0c632f
13 changed files with 153 additions and 21 deletions
@@ -18,13 +18,29 @@ import Combine
import SwiftUI
struct RoomNotificationSettingsScreenCoordinatorParameters {
weak var navigationStackCoordinator: NavigationStackCoordinator?
let notificationSettingsProxy: NotificationSettingsProxyProtocol
let roomProxy: RoomProxyProtocol
}
enum RoomNotificationSettingsScreenCoordinatorAction {
case presentNotificationSettingsScreen
}
final class RoomNotificationSettingsScreenCoordinator: CoordinatorProtocol {
private let parameters: RoomNotificationSettingsScreenCoordinatorParameters
private var viewModel: RoomNotificationSettingsScreenViewModelProtocol
private let actionsSubject: PassthroughSubject<RoomNotificationSettingsScreenCoordinatorAction, Never> = .init()
private var cancellables: Set<AnyCancellable> = .init()
var actions: AnyPublisher<RoomNotificationSettingsScreenCoordinatorAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
private var navigationStackCoordinator: NavigationStackCoordinator? {
parameters.navigationStackCoordinator
}
init(parameters: RoomNotificationSettingsScreenCoordinatorParameters) {
self.parameters = parameters
@@ -32,7 +48,14 @@ final class RoomNotificationSettingsScreenCoordinator: CoordinatorProtocol {
roomProxy: parameters.roomProxy)
}
func start() { }
func start() {
viewModel.actions.sink { [weak self] action in
switch action {
case .openGlobalSettings:
self?.actionsSubject.send(.presentNotificationSettingsScreen)
}
}.store(in: &cancellables)
}
func toPresentable() -> AnyView {
AnyView(RoomNotificationSettingsScreen(context: viewModel.context))
@@ -16,7 +16,9 @@
import Foundation
enum RoomNotificationSettingsScreenViewModelAction { }
enum RoomNotificationSettingsScreenViewModelAction {
case openGlobalSettings
}
enum RoomNotificationSettingsState {
case loading
@@ -66,15 +68,20 @@ struct RoomNotificationSettingsScreenViewStateBindings {
enum RoomNotificationSettingsScreenViewAction {
case changedAllowCustomSettings
case setCustomMode(RoomNotificationModeProxy)
case customSettingFootnoteLinkTapped
}
struct RoomNotificationSettingsScreenStrings {
let customSettingFootnote: AttributedString
let customSettingFootnoteLink: URL?
init() {
customSettingFootnoteLink = URL(string: "element://openGlobalSettings")
let linkPlaceholder = "{link}"
var customSettingFootnote = AttributedString(L10n.screenRoomNotificationSettingsDefaultSettingFootnote(linkPlaceholder))
var linkString = AttributedString(L10n.screenRoomNotificationSettingsDefaultSettingFootnoteContentLink)
linkString.link = customSettingFootnoteLink
linkString.bold()
customSettingFootnote.replace(linkPlaceholder, with: linkString)
@@ -48,6 +48,8 @@ class RoomNotificationSettingsScreenViewModel: RoomNotificationSettingsScreenVie
toogleCustomSetting()
case .setCustomMode(let mode):
setCustomMode(mode)
case .customSettingFootnoteLinkTapped:
actionsSubject.send(.openGlobalSettings)
}
}
@@ -71,6 +71,11 @@ struct RoomNotificationSettingsScreen: View {
.compoundFormSectionHeader()
} footer: {
Text(context.viewState.strings.customSettingFootnote)
.environment(\.openURL, OpenURLAction { url in
guard url == context.viewState.strings.customSettingFootnoteLink else { return .discarded }
context.send(viewAction: .customSettingFootnoteLinkTapped)
return .handled
})
.compoundFormSectionFooter()
}
.compoundFormSection()