* Redesigned permissions screen # Conflicts: # ElementX.xcodeproj/project.pbxproj * updated tests * update proj * fix pseudo language tests
88 lines
2.9 KiB
Swift
88 lines
2.9 KiB
Swift
//
|
|
// Copyright 2025 Element Creations Ltd.
|
|
// Copyright 2022-2025 New Vector Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
|
// Please see LICENSE files in the repository root for full details.
|
|
//
|
|
|
|
import Compound
|
|
import SwiftUI
|
|
|
|
struct RoomChangePermissionsScreen: View {
|
|
@Bindable var context: RoomChangePermissionsScreenViewModel.Context
|
|
|
|
var body: some View {
|
|
Form {
|
|
ForEach(RoomChangePermissionsScreenGroup.allCases, id: \.self) { group in
|
|
section(for: group)
|
|
}
|
|
}
|
|
.compoundList()
|
|
.navigationTitle(L10n.screenRoomChangePermissionsTitle)
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.navigationBarBackButtonHidden(context.viewState.hasChanges)
|
|
.toolbar { toolbar }
|
|
.alert(item: $context.alertInfo)
|
|
}
|
|
|
|
@ViewBuilder
|
|
private func section(for group: RoomChangePermissionsScreenGroup) -> some View {
|
|
if let settings = Binding($context.settings[group]) {
|
|
Section {
|
|
ForEach(settings) { $setting in
|
|
ListRow(label: .plain(title: setting.title),
|
|
kind: .picker(selection: $setting.value, items: setting.allValues))
|
|
}
|
|
} header: {
|
|
Text(group.name)
|
|
.compoundListSectionHeader()
|
|
}
|
|
}
|
|
}
|
|
|
|
@ToolbarContentBuilder
|
|
var toolbar: some ToolbarContent {
|
|
ToolbarItem(placement: .confirmationAction) {
|
|
Button(L10n.actionSave) {
|
|
context.send(viewAction: .save)
|
|
}
|
|
.disabled(!context.viewState.hasChanges)
|
|
}
|
|
|
|
if context.viewState.hasChanges {
|
|
ToolbarItem(placement: .cancellationAction) {
|
|
Button(L10n.actionCancel) {
|
|
context.send(viewAction: .cancel)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Previews
|
|
|
|
struct RoomChangePermissionsScreen_Previews: PreviewProvider, TestablePreview {
|
|
static let roomViewModel = makeViewModel(isSpace: false)
|
|
static let spaceViewModel = makeViewModel(isSpace: true)
|
|
|
|
static var previews: some View {
|
|
NavigationStack {
|
|
RoomChangePermissionsScreen(context: roomViewModel.context)
|
|
}
|
|
.previewDisplayName("Room")
|
|
|
|
NavigationStack {
|
|
RoomChangePermissionsScreen(context: spaceViewModel.context)
|
|
}
|
|
.previewDisplayName("Space")
|
|
}
|
|
|
|
static func makeViewModel(isSpace: Bool) -> RoomChangePermissionsScreenViewModel {
|
|
RoomChangePermissionsScreenViewModel(currentPermissions: .init(powerLevels: .mock),
|
|
roomProxy: JoinedRoomProxyMock(.init(isSpace: isSpace)),
|
|
userIndicatorController: UserIndicatorControllerMock(),
|
|
analytics: ServiceLocator.shared.analytics)
|
|
}
|
|
}
|