Display the list of rooms with user-defined notification settings (#1535)

This commit is contained in:
Nicolas Mauri
2023-08-22 14:33:39 +02:00
committed by GitHub
parent db1903ec05
commit b1ea23c925
34 changed files with 760 additions and 129 deletions
@@ -0,0 +1,57 @@
//
// Copyright 2023 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Compound
import SwiftUI
struct RoomNotificationSettingsCustomSectionView: View {
@ObservedObject var context: RoomNotificationSettingsScreenViewModel.Context
var body: some View {
Section {
ForEach(context.viewState.availableCustomRoomNotificationModes, id: \.self) { mode in
ListRow(label: .plain(title: context.viewState.strings.string(for: mode)),
details: (context.viewState.pendingCustomMode == mode) ? .isWaiting(true) : nil,
kind: .selection(isSelected: context.viewState.isSelected(mode: mode)) {
context.send(viewAction: .setCustomMode(mode))
})
.disabled(context.viewState.pendingCustomMode != nil)
}
} header: {
Text(context.viewState.customSettingsSectionHeader)
.compoundListSectionHeader()
}
}
}
struct RoomNotificationSettingsCustomSectionView_Previews: PreviewProvider {
static let viewModel = {
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init(defaultRoomMode: .allMessages, roomMode: .mentionsAndKeywordsOnly))
let roomProxy = RoomProxyMock(with: .init(displayName: "Room", isEncrypted: true, joinedMembersCount: 4))
return RoomNotificationSettingsScreenViewModel(notificationSettingsProxy: notificationSettingsProxy,
roomProxy: roomProxy,
displayAsUserDefinedRoomSettings: false)
}()
static var previews: some View {
Form {
RoomNotificationSettingsCustomSectionView(context: viewModel.context)
}
.compoundForm()
}
}
@@ -31,14 +31,13 @@ struct RoomNotificationSettingsScreen: View {
}
}
.compoundList()
.navigationTitle(L10n.screenRoomDetailsNotificationTitle)
.navigationTitle(context.viewState.navigationTitle)
.alert(item: $context.alertInfo)
.track(screen: .roomNotifications)
}
// MARK: - Private
@ViewBuilder
private var allowCustomSettingSection: some View {
Section {
ListRow(label: .plain(title: L10n.screenRoomNotificationSettingsAllowCustom),
@@ -54,7 +53,6 @@ struct RoomNotificationSettingsScreen: View {
}
}
@ViewBuilder
private var defaultSettingSection: some View {
Section {
ListRow(label: .plain(title: context.viewState.isRestoringDefaultSetting ? L10n.commonLoading : context.viewState.strings.string(for: context.viewState.notificationSettingsState)),
@@ -74,21 +72,8 @@ struct RoomNotificationSettingsScreen: View {
}
}
@ViewBuilder
private var customSettingsSection: some View {
Section {
ListRow(label: .plain(title: L10n.screenRoomNotificationSettingsCustomSettingsTitle),
kind: .inlinePicker(selection: $context.customMode,
items: context.viewState.availableCustomRoomNotificationModes.map {
(title: context.viewState.strings.string(for: $0), tag: $0)
}))
.onChange(of: context.customMode) { mode in
context.send(viewAction: .setCustomMode(mode))
}
} header: {
Text(L10n.screenRoomNotificationSettingsCustomSettingsTitle)
.compoundListSectionHeader()
}
RoomNotificationSettingsCustomSectionView(context: context)
}
}
@@ -100,10 +85,9 @@ struct RoomNotificationSettingsScreen_Previews: PreviewProvider {
let roomProxy = RoomProxyMock(with: .init(displayName: "Room", isEncrypted: true, joinedMembersCount: 4))
let model = RoomNotificationSettingsScreenViewModel(notificationSettingsProxy: notificationSettingsProxy,
roomProxy: roomProxy)
return model
return RoomNotificationSettingsScreenViewModel(notificationSettingsProxy: notificationSettingsProxy,
roomProxy: roomProxy,
displayAsUserDefinedRoomSettings: false)
}()
static let viewModelCustom = {
@@ -111,12 +95,11 @@ struct RoomNotificationSettingsScreen_Previews: PreviewProvider {
let roomProxy = RoomProxyMock(with: .init(displayName: "Room", isEncrypted: true, joinedMembersCount: 4))
let model = RoomNotificationSettingsScreenViewModel(notificationSettingsProxy: notificationSettingsProxy,
roomProxy: roomProxy)
return model
return RoomNotificationSettingsScreenViewModel(notificationSettingsProxy: notificationSettingsProxy,
roomProxy: roomProxy,
displayAsUserDefinedRoomSettings: false)
}()
static var previews: some View {
RoomNotificationSettingsScreen(context: viewModel.context)
.previewDisplayName("Default")
@@ -0,0 +1,65 @@
//
// Copyright 2023 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Compound
import SwiftUI
struct RoomNotificationSettingsUserDefinedScreen: View {
@ObservedObject var context: RoomNotificationSettingsScreenViewModel.Context
var body: some View {
Form {
RoomNotificationSettingsCustomSectionView(context: context)
deleteButton
}
.compoundList()
.navigationTitle(context.viewState.navigationTitle)
.alert(item: $context.alertInfo)
.track(screen: .roomNotifications)
}
// MARK: - Private
private var deleteButton: some View {
ListRow(label: .action(title: L10n.screenRoomNotificationSettingsEditRemoveSetting,
systemIcon: .trash,
role: .destructive),
details: context.viewState.deletingCustomSetting ? .isWaiting(true) : nil,
kind: .button {
context.send(viewAction: .deleteCustomSettingTapped)
})
.disabled(context.viewState.deletingCustomSetting)
}
}
// MARK: - Previews
struct RoomNotificationSettingsUserDefinedScreen_Previews: PreviewProvider {
static let viewModel = {
let notificationSettingsProxy = NotificationSettingsProxyMock(with: .init(defaultRoomMode: .mentionsAndKeywordsOnly, roomMode: .mentionsAndKeywordsOnly))
let roomProxy = RoomProxyMock(with: .init(displayName: "Room", isEncrypted: true, joinedMembersCount: 4))
return RoomNotificationSettingsScreenViewModel(notificationSettingsProxy: notificationSettingsProxy,
roomProxy: roomProxy,
displayAsUserDefinedRoomSettings: true)
}()
static var previews: some View {
RoomNotificationSettingsUserDefinedScreen(context: viewModel.context)
}
}