implemented the UI to manage authorized spaces

This commit is contained in:
Mauro Romito
2025-11-28 17:45:37 +01:00
committed by Mauro
parent 2968f67514
commit cfbc68f4f7
7 changed files with 189 additions and 11 deletions

View File

@@ -100,6 +100,32 @@ extension [SpaceRoomProxyProtocol] {
]
}
static var mockJoinedSpaces2: [SpaceRoomProxyMock] {
[
SpaceRoomProxyMock(.init(id: "space1",
name: "The Foundation",
avatarURL: .mockMXCAvatar,
isSpace: true,
childrenCount: 1,
joinedMembersCount: 500,
canonicalAlias: "#the-foundation:matrix.org",
state: .joined)),
SpaceRoomProxyMock(.init(id: "space2",
name: "The Second Foundation",
isSpace: true,
childrenCount: 1,
joinedMembersCount: 100,
state: .joined)),
SpaceRoomProxyMock(.init(id: "space3",
name: "The Galactic Empire",
isSpace: true,
childrenCount: 25000,
joinedMembersCount: 1_000_000_000,
canonicalAlias: "#the-galactic-empire:matrix.org",
state: .joined))
]
}
static var mockSpaceList: [SpaceRoomProxyProtocol] {
makeSpaceRooms(isSpace: true) + makeSpaceRooms(isSpace: false)
}

View File

@@ -138,6 +138,7 @@ enum RoomAvatarSizeOnScreen {
case chats
case spaces
case spaceSettings
case authorizedSpaces
case timeline
case leaveSpace
case messageForwarding
@@ -154,14 +155,11 @@ enum RoomAvatarSizeOnScreen {
switch self {
case .chats, .spaces, .spaceSettings:
return 52
case .timeline, .leaveSpace:
case .timeline, .leaveSpace, .roomDirectorySearch,
.completionSuggestions, .authorizedSpaces:
return 32
case .notificationSettings:
return 30
case .roomDirectorySearch:
return 32
case .completionSuggestions:
return 32
case .messageForwarding:
return 36
case .globalSearch:

View File

@@ -0,0 +1,48 @@
//
// Copyright 2025 Element Creations 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 ToolbarButton: View {
enum Role {
case cancel
case done
var title: String {
switch self {
case .cancel:
L10n.actionCancel
case .done:
L10n.actionDone
}
}
var icon: CompoundIcon {
switch self {
case .cancel:
CompoundIcon(\.close)
case .done:
CompoundIcon(\.check)
}
}
}
let role: Role
let action: () -> Void
var body: some View {
if #available(iOS 26, *) {
Button(action: action) {
role.icon
.accessibilityLabel(role.title)
}
} else {
Button(role.title, action: action)
}
}
}

View File

@@ -19,13 +19,21 @@ struct ManageAuthorizedSpacesScreenViewState: BindableState {
authorizedSpacesSelection.selectedIDs != desiredSelectedIDs
}
var isDoneButtonDisabled: Bool {
desiredSelectedIDs.isEmpty || !hasChanges
}
init(authorizedSpacesSelection: AuthorizedSpacesSelection) {
self.authorizedSpacesSelection = authorizedSpacesSelection
desiredSelectedIDs = authorizedSpacesSelection.selectedIDs
}
}
enum ManageAuthorizedSpacesScreenViewAction { }
enum ManageAuthorizedSpacesScreenViewAction {
case cancel
case done
case toggle(spaceID: String)
}
struct AuthorizedSpacesSelection {
let joinedParentSpaces: [SpaceRoomProxyProtocol]

View File

@@ -26,5 +26,18 @@ class ManageAuthorizedSpacesScreenViewModel: ManageAuthorizedSpacesScreenViewMod
override func process(viewAction: ManageAuthorizedSpacesScreenViewAction) {
MXLog.info("View model: received view action: \(viewAction)")
switch viewAction {
case .cancel:
actionsSubject.send(.dismiss)
case .done:
// TODO: Implement
break
case .toggle(let spaceID):
if state.desiredSelectedIDs.contains(spaceID) {
state.desiredSelectedIDs.remove(spaceID)
} else {
state.desiredSelectedIDs.insert(spaceID)
}
}
}
}

View File

@@ -12,16 +12,95 @@ struct ManageAuthorizedSpacesScreen: View {
@Bindable var context: ManageAuthorizedSpacesScreenViewModel.Context
var body: some View {
Form { }
.compoundList()
.navigationTitle("Manage spaces")
Form {
header
if !context.viewState.authorizedSpacesSelection.joinedParentSpaces.isEmpty {
joinedParentsSection
}
if !context.viewState.authorizedSpacesSelection.unknownSpacesIDs.isEmpty {
unkwnownSpacesSection
}
}
.compoundList()
.navigationTitle(L10n.screenManageAuthorizedSpacesTitle)
.navigationBarTitleDisplayMode(.inline)
.toolbar { toolbar }
}
private var header: some View {
Section {
EmptyView()
} header: {
VStack(spacing: 16) {
BigIcon(icon: \.spaceSolid, style: .default)
.accessibilityHidden(true)
Text(L10n.screenManageAuthorizedSpacesHeader)
.multilineTextAlignment(.center)
.font(.compound.headingMDBold)
.foregroundStyle(.compound.textPrimary)
.padding(.horizontal, 24)
}
.frame(maxWidth: .infinity)
}
}
private var joinedParentsSection: some View {
Section {
ForEach(context.viewState.authorizedSpacesSelection.joinedParentSpaces, id: \.id) { space in
ListRow(label: .avatar(title: space.name,
description: space.canonicalAlias,
icon: avatar(space: space)),
kind: .multiSelection(isSelected: context.viewState.desiredSelectedIDs.contains(space.id)) {
context.send(viewAction: .toggle(spaceID: space.id))
})
}
} header: {
Text(L10n.screenManageAuthorizedSpacesYourSpacesSectionTitle)
.compoundListSectionHeader()
}
}
private var unkwnownSpacesSection: some View {
Section {
ForEach(context.viewState.authorizedSpacesSelection.unknownSpacesIDs, id: \.self) { id in
ListRow(label: .plain(title: L10n.screenManageAuthorizedSpacesUnknownSpace,
description: id),
kind: .multiSelection(isSelected: context.viewState.desiredSelectedIDs.contains(id)) {
context.send(viewAction: .toggle(spaceID: id))
})
}
} header: {
Text(L10n.screenManageAuthorizedSpacesUnknownSpacesSectionTitle)
.compoundListSectionHeader()
}
}
private func avatar(space: SpaceRoomProxyProtocol) -> some View {
RoomAvatarImage(avatar: space.avatar,
avatarSize: .room(on: .authorizedSpaces),
mediaProvider: context.mediaProvider)
}
@ToolbarContentBuilder
private var toolbar: some ToolbarContent {
ToolbarItem(placement: .confirmationAction) {
ToolbarButton(role: .done) {
context.send(viewAction: .done)
}
.disabled(context.viewState.isDoneButtonDisabled)
}
ToolbarItem(placement: .cancellationAction) {
ToolbarButton(role: .cancel) {
context.send(viewAction: .cancel)
}
}
}
}
// MARK: - Previews
struct ManageAuthorizedSpacesScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = ManageAuthorizedSpacesScreenViewModel(authorizedSpacesSelection: .init(joinedParentSpaces: .mockJoinedSpaces,
static let viewModel = ManageAuthorizedSpacesScreenViewModel(authorizedSpacesSelection: .init(joinedParentSpaces: .mockJoinedSpaces2,
unknownSpacesIDs: ["!unknown-space-id-1",
"!unknown-space-id-2",
"!unknown-space-id-3"],
@@ -31,6 +110,8 @@ struct ManageAuthorizedSpacesScreen_Previews: PreviewProvider, TestablePreview {
mediaProvider: MediaProviderMock(configuration: .init()))
static var previews: some View {
ManageAuthorizedSpacesScreen(context: viewModel.context)
NavigationStack {
ManageAuthorizedSpacesScreen(context: viewModel.context)
}
}
}