diff --git a/ElementX.xcodeproj/project.pbxproj b/ElementX.xcodeproj/project.pbxproj index 709ec2fde..603321ca2 100644 --- a/ElementX.xcodeproj/project.pbxproj +++ b/ElementX.xcodeproj/project.pbxproj @@ -961,6 +961,7 @@ A6FFC4C5154C446BAD6B40D8 /* TimelineItemProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8520AFD6680CBAD388F6D927 /* TimelineItemProvider.swift */; }; A722F426FD81FC67706BB1E0 /* CustomLayoutLabelStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42236480CF0431535EBE8387 /* CustomLayoutLabelStyle.swift */; }; A74438ED16F8683A4B793E6A /* AnalyticsSettingsScreenViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BCE3FAF40932AC7C7639AC4 /* AnalyticsSettingsScreenViewModel.swift */; }; + A7B854782EDA0494005AF85E /* ToolbarButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7B854772EDA0489005AF85E /* ToolbarButton.swift */; }; A7D48E44D485B143AADDB77D /* Strings+Untranslated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A18F6CE4D694D21E4EA9B25 /* Strings+Untranslated.swift */; }; A7DB75E090542331F6668A23 /* CreateRoomScreenViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF19027E7FFA5E63D148873A /* CreateRoomScreenViewModel.swift */; }; A808DC3F72D15C6C5A52317E /* TimelineItemDebugView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCDA016D05107DED3B9495CB /* TimelineItemDebugView.swift */; }; @@ -2397,6 +2398,7 @@ A768CA51A59B8A5D8C8FD599 /* AuthenticationStartScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationStartScreen.swift; sourceTree = ""; }; A7978C9EFBDD7DE39BD86726 /* RestorationTokenTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestorationTokenTests.swift; sourceTree = ""; }; A7A1B80FE6E3BA72F9C748AD /* AdvancedSettingsScreenViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdvancedSettingsScreenViewModel.swift; sourceTree = ""; }; + A7B854772EDA0489005AF85E /* ToolbarButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToolbarButton.swift; sourceTree = ""; }; A7C4EA55DA62F9D0F984A2AE /* CollapsibleTimelineItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollapsibleTimelineItem.swift; sourceTree = ""; }; A7D452AF7B5F7E3A0A7DB54C /* SessionVerificationScreenViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionVerificationScreenViewModelProtocol.swift; sourceTree = ""; }; A7E37072597F67C4DD8CC2DB /* ComposerDraftServiceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComposerDraftServiceProtocol.swift; sourceTree = ""; }; @@ -3634,6 +3636,7 @@ 328DD5DA1281F758B72006C7 /* Views */ = { isa = PBXGroup; children = ( + A7B854772EDA0489005AF85E /* ToolbarButton.swift */, 8F21ED7205048668BEB44A38 /* AppActivityView.swift */, CC743C7A85E3171BCBF0A653 /* AvatarHeaderView.swift */, 9A028783CFFF861C5E44FFB1 /* BadgeLabel.swift */, @@ -8064,6 +8067,7 @@ F54E2D6CAD96E1AC15BC526F /* MessageForwardingScreenViewModel.swift in Sources */, C13128AAA787A4C2CBE4EE82 /* MessageForwardingScreenViewModelProtocol.swift in Sources */, C97325EFDCCEE457432A9E82 /* MessageText.swift in Sources */, + A7B854782EDA0494005AF85E /* ToolbarButton.swift in Sources */, AF2ABA2794E376B64104C964 /* MockSoftLogoutScreenState.swift in Sources */, 530C2238E40F71223327FC95 /* MockTimelineController.swift in Sources */, E938F7A45D6A3DBBE6789A03 /* NSEUserSession.swift in Sources */, diff --git a/ElementX/Sources/Mocks/SpaceRoomProxyMock.swift b/ElementX/Sources/Mocks/SpaceRoomProxyMock.swift index 85e6df1fb..c85aa7017 100644 --- a/ElementX/Sources/Mocks/SpaceRoomProxyMock.swift +++ b/ElementX/Sources/Mocks/SpaceRoomProxyMock.swift @@ -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) } diff --git a/ElementX/Sources/Other/Avatars.swift b/ElementX/Sources/Other/Avatars.swift index 4ac8c9c68..926673886 100644 --- a/ElementX/Sources/Other/Avatars.swift +++ b/ElementX/Sources/Other/Avatars.swift @@ -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: diff --git a/ElementX/Sources/Other/SwiftUI/Views/ToolbarButton.swift b/ElementX/Sources/Other/SwiftUI/Views/ToolbarButton.swift new file mode 100644 index 000000000..6dfee0eb6 --- /dev/null +++ b/ElementX/Sources/Other/SwiftUI/Views/ToolbarButton.swift @@ -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) + } + } +} diff --git a/ElementX/Sources/Screens/ManageAuthorizedSpacesScreen/ManageAuthorizedSpacesScreenModels.swift b/ElementX/Sources/Screens/ManageAuthorizedSpacesScreen/ManageAuthorizedSpacesScreenModels.swift index 96e940a27..ce0b38d5e 100644 --- a/ElementX/Sources/Screens/ManageAuthorizedSpacesScreen/ManageAuthorizedSpacesScreenModels.swift +++ b/ElementX/Sources/Screens/ManageAuthorizedSpacesScreen/ManageAuthorizedSpacesScreenModels.swift @@ -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] diff --git a/ElementX/Sources/Screens/ManageAuthorizedSpacesScreen/ManageAuthorizedSpacesScreenViewModel.swift b/ElementX/Sources/Screens/ManageAuthorizedSpacesScreen/ManageAuthorizedSpacesScreenViewModel.swift index 5cb8bf189..e5f766ca4 100644 --- a/ElementX/Sources/Screens/ManageAuthorizedSpacesScreen/ManageAuthorizedSpacesScreenViewModel.swift +++ b/ElementX/Sources/Screens/ManageAuthorizedSpacesScreen/ManageAuthorizedSpacesScreenViewModel.swift @@ -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) + } + } } } diff --git a/ElementX/Sources/Screens/ManageAuthorizedSpacesScreen/View/ManageAuthorizedSpacesScreen.swift b/ElementX/Sources/Screens/ManageAuthorizedSpacesScreen/View/ManageAuthorizedSpacesScreen.swift index e68e7932f..b29d24cee 100644 --- a/ElementX/Sources/Screens/ManageAuthorizedSpacesScreen/View/ManageAuthorizedSpacesScreen.swift +++ b/ElementX/Sources/Screens/ManageAuthorizedSpacesScreen/View/ManageAuthorizedSpacesScreen.swift @@ -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) + } } }