mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-09 16:22:55 +00:00
ff5dcb040d
Removes the ServiceLocator singleton and instead directly injects the dependencies it was holding for more control over instantiation of the various component subtrees and better visibility over how they're being used.
97 lines
3.4 KiB
Swift
97 lines
3.4 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.roleValue,
|
|
items: setting.availableValues))
|
|
.disabled(setting.isDisabled)
|
|
}
|
|
} 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 roomAsUserViewModel = makeViewModel(isSpace: false, ownPowerLevel: RoomRole.user.powerLevel)
|
|
static let spaceViewModel = makeViewModel(isSpace: true)
|
|
|
|
static var previews: some View {
|
|
ElementNavigationStack {
|
|
RoomChangePermissionsScreen(context: roomViewModel.context)
|
|
}
|
|
.previewDisplayName("Room")
|
|
|
|
ElementNavigationStack {
|
|
RoomChangePermissionsScreen(context: roomAsUserViewModel.context)
|
|
}
|
|
.previewDisplayName("Room as User")
|
|
|
|
ElementNavigationStack {
|
|
RoomChangePermissionsScreen(context: spaceViewModel.context)
|
|
}
|
|
.previewDisplayName("Space")
|
|
}
|
|
|
|
static func makeViewModel(isSpace: Bool, ownPowerLevel: RoomPowerLevel = RoomRole.creator.powerLevel) -> RoomChangePermissionsScreenViewModel {
|
|
RoomChangePermissionsScreenViewModel(currentPermissions: .init(powerLevels: .mock),
|
|
ownPowerLevel: ownPowerLevel,
|
|
roomProxy: JoinedRoomProxyMock(.init(isSpace: isSpace)),
|
|
userIndicatorController: UserIndicatorControllerMock(),
|
|
analytics: .mock())
|
|
}
|
|
}
|