mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Add RoomChangePermissionsScreen (#2513)
This commit is contained in:
+83
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// Copyright 2022 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 RoomChangePermissionsScreen: View {
|
||||
@ObservedObject var context: RoomChangePermissionsScreenViewModel.Context
|
||||
|
||||
var body: some View {
|
||||
Form {
|
||||
ForEach($context.settings) { $setting in
|
||||
Section {
|
||||
ListRow(label: .plain(title: setting.title),
|
||||
kind: .inlinePicker(selection: $setting.value, items: setting.allValues))
|
||||
} header: {
|
||||
Text(setting.title)
|
||||
.compoundListSectionHeader()
|
||||
}
|
||||
}
|
||||
}
|
||||
.compoundList()
|
||||
.navigationTitle(context.viewState.title)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar { toolbar }
|
||||
.alert(item: $context.alertInfo)
|
||||
}
|
||||
|
||||
@ToolbarContentBuilder
|
||||
var toolbar: some ToolbarContent {
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button(L10n.actionSave) {
|
||||
context.send(viewAction: .save)
|
||||
}
|
||||
.disabled(!context.viewState.hasChanges)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct RoomChangePermissionsScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let detailsViewModel = makeViewModel(group: .roomDetails)
|
||||
static let messagesViewModel = makeViewModel(group: .messagesAndContent)
|
||||
static let membersViewModel = makeViewModel(group: .memberModeration)
|
||||
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
RoomChangePermissionsScreen(context: detailsViewModel.context)
|
||||
}
|
||||
.previewDisplayName("Room details")
|
||||
|
||||
NavigationStack {
|
||||
RoomChangePermissionsScreen(context: messagesViewModel.context)
|
||||
}
|
||||
.previewDisplayName("Messages and Content")
|
||||
|
||||
NavigationStack {
|
||||
RoomChangePermissionsScreen(context: membersViewModel.context)
|
||||
}
|
||||
.previewDisplayName("Member moderation")
|
||||
}
|
||||
|
||||
static func makeViewModel(group: RoomRolesAndPermissionsScreenPermissionsGroup) -> RoomChangePermissionsScreenViewModel {
|
||||
RoomChangePermissionsScreenViewModel(currentPermissions: .default,
|
||||
group: group,
|
||||
roomProxy: RoomProxyMock(with: .init()),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user