mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
Add the initial implementation for managing spaces. (#4963)
This isn't hooked up into the flows yet.
This commit is contained in:
@@ -276,6 +276,7 @@
|
||||
"common_reason" = "Reason";
|
||||
"common_recovery_key" = "Recovery key";
|
||||
"common_refreshing" = "Refreshing…";
|
||||
"common_removing" = "Removing…";
|
||||
"common_replying_to" = "Replying to %1$@";
|
||||
"common_report_a_bug" = "Report a bug";
|
||||
"common_report_a_problem" = "Report a problem";
|
||||
@@ -718,6 +719,8 @@
|
||||
"screen_security_and_privacy_room_visibility_section_header" = "Visibility";
|
||||
"screen_security_and_privacy_title" = "Security & privacy";
|
||||
"screen_space_menu_action_members" = "View members";
|
||||
"screen_space_remove_rooms_confirmation_content" = "Removing a room will not affect the room access. To change the access go to Room info > Privacy & security.";
|
||||
"screen_space_remove_rooms_confirmation_title_ios" = "Remove rooms from %1$@?";
|
||||
"screen_space_add_rooms_room_access_description" = "Adding a room will not affect the room access. To change the access go to Room info > Privacy & security.";
|
||||
"screen_space_announcement_item1" = "View spaces you've created or joined";
|
||||
"screen_space_announcement_item2" = "Accept or decline invites to spaces";
|
||||
|
||||
@@ -276,6 +276,7 @@
|
||||
"common_reason" = "Reason";
|
||||
"common_recovery_key" = "Recovery key";
|
||||
"common_refreshing" = "Refreshing…";
|
||||
"common_removing" = "Removing…";
|
||||
"common_replying_to" = "Replying to %1$@";
|
||||
"common_report_a_bug" = "Report a bug";
|
||||
"common_report_a_problem" = "Report a problem";
|
||||
@@ -718,6 +719,8 @@
|
||||
"screen_security_and_privacy_room_visibility_section_header" = "Visibility";
|
||||
"screen_security_and_privacy_title" = "Security & privacy";
|
||||
"screen_space_menu_action_members" = "View members";
|
||||
"screen_space_remove_rooms_confirmation_content" = "Removing a room will not affect the room access. To change the access go to Room info > Privacy & security.";
|
||||
"screen_space_remove_rooms_confirmation_title_ios" = "Remove rooms from %1$@?";
|
||||
"screen_space_add_rooms_room_access_description" = "Adding a room will not affect the room access. To change the access go to Room info > Privacy & security.";
|
||||
"screen_space_announcement_item1" = "View spaces you've created or joined";
|
||||
"screen_space_announcement_item2" = "Accept or decline invites to spaces";
|
||||
|
||||
@@ -130,6 +130,22 @@
|
||||
<string>%1$d Rooms</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>common_selected_count</key>
|
||||
<dict>
|
||||
<key>NSStringLocalizedFormatKey</key>
|
||||
<string>%#@COUNT@</string>
|
||||
<key>COUNT</key>
|
||||
<dict>
|
||||
<key>NSStringFormatSpecTypeKey</key>
|
||||
<string>NSStringPluralRuleType</string>
|
||||
<key>NSStringFormatValueTypeKey</key>
|
||||
<string>d</string>
|
||||
<key>one</key>
|
||||
<string>%1$d selected</string>
|
||||
<key>other</key>
|
||||
<string>%1$d selected</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>common_spaces</key>
|
||||
<dict>
|
||||
<key>NSStringLocalizedFormatKey</key>
|
||||
@@ -450,6 +466,22 @@
|
||||
<string>%1$@ are typing</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>screen_space_remove_rooms_confirmation_title</key>
|
||||
<dict>
|
||||
<key>NSStringLocalizedFormatKey</key>
|
||||
<string>%#@COUNT@</string>
|
||||
<key>COUNT</key>
|
||||
<dict>
|
||||
<key>NSStringFormatSpecTypeKey</key>
|
||||
<string>NSStringPluralRuleType</string>
|
||||
<key>NSStringFormatValueTypeKey</key>
|
||||
<string>d</string>
|
||||
<key>one</key>
|
||||
<string>Remove %1$d room from %2$@</string>
|
||||
<key>other</key>
|
||||
<string>Remove %1$d rooms from %2$@</string>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>troubleshoot_notifications_test_blocked_users_result_some</key>
|
||||
<dict>
|
||||
<key>NSStringLocalizedFormatKey</key>
|
||||
|
||||
@@ -620,6 +620,8 @@ internal enum L10n {
|
||||
internal static var commonRecoveryKey: String { return L10n.tr("Localizable", "common_recovery_key") }
|
||||
/// Refreshing…
|
||||
internal static var commonRefreshing: String { return L10n.tr("Localizable", "common_refreshing") }
|
||||
/// Removing…
|
||||
internal static var commonRemoving: String { return L10n.tr("Localizable", "common_removing") }
|
||||
/// Plural format key: "%#@COUNT@"
|
||||
internal static func commonReplies(_ p1: Int) -> String {
|
||||
return L10n.tr("Localizable", "common_replies", p1)
|
||||
@@ -660,6 +662,10 @@ internal enum L10n {
|
||||
internal static var commonSecurity: String { return L10n.tr("Localizable", "common_security") }
|
||||
/// Seen by
|
||||
internal static var commonSeenBy: String { return L10n.tr("Localizable", "common_seen_by") }
|
||||
/// Plural format key: "%#@COUNT@"
|
||||
internal static func commonSelectedCount(_ p1: Int) -> String {
|
||||
return L10n.tr("Localizable", "common_selected_count", p1)
|
||||
}
|
||||
/// Send to
|
||||
internal static var commonSendTo: String { return L10n.tr("Localizable", "common_send_to") }
|
||||
/// Sending…
|
||||
@@ -3155,6 +3161,16 @@ internal enum L10n {
|
||||
internal static var screenSpaceListTitle: String { return L10n.tr("Localizable", "screen_space_list_title") }
|
||||
/// View members
|
||||
internal static var screenSpaceMenuActionMembers: String { return L10n.tr("Localizable", "screen_space_menu_action_members") }
|
||||
/// Removing a room will not affect the room access. To change the access go to Room info > Privacy & security.
|
||||
internal static var screenSpaceRemoveRoomsConfirmationContent: String { return L10n.tr("Localizable", "screen_space_remove_rooms_confirmation_content") }
|
||||
/// Plural format key: "%#@COUNT@"
|
||||
internal static func screenSpaceRemoveRoomsConfirmationTitle(_ p1: Int) -> String {
|
||||
return L10n.tr("Localizable", "screen_space_remove_rooms_confirmation_title", p1)
|
||||
}
|
||||
/// Remove rooms from %1$@?
|
||||
internal static func screenSpaceRemoveRoomsConfirmationTitleIos(_ p1: Any) -> String {
|
||||
return L10n.tr("Localizable", "screen_space_remove_rooms_confirmation_title_ios", String(describing: p1))
|
||||
}
|
||||
/// Leave space
|
||||
internal static var screenSpaceSettingsLeaveSpace: String { return L10n.tr("Localizable", "screen_space_settings_leave_space") }
|
||||
/// Roles & permissions
|
||||
|
||||
@@ -17130,6 +17130,76 @@ class SpaceServiceProxyMock: SpaceServiceProxyProtocol, @unchecked Sendable {
|
||||
return addChildToReturnValue
|
||||
}
|
||||
}
|
||||
//MARK: - removeChild
|
||||
|
||||
var removeChildFromUnderlyingCallsCount = 0
|
||||
var removeChildFromCallsCount: Int {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return removeChildFromUnderlyingCallsCount
|
||||
} else {
|
||||
var returnValue: Int? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = removeChildFromUnderlyingCallsCount
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
removeChildFromUnderlyingCallsCount = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
removeChildFromUnderlyingCallsCount = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var removeChildFromCalled: Bool {
|
||||
return removeChildFromCallsCount > 0
|
||||
}
|
||||
var removeChildFromReceivedArguments: (childID: String, spaceID: String)?
|
||||
var removeChildFromReceivedInvocations: [(childID: String, spaceID: String)] = []
|
||||
|
||||
var removeChildFromUnderlyingReturnValue: Result<Void, SpaceServiceProxyError>!
|
||||
var removeChildFromReturnValue: Result<Void, SpaceServiceProxyError>! {
|
||||
get {
|
||||
if Thread.isMainThread {
|
||||
return removeChildFromUnderlyingReturnValue
|
||||
} else {
|
||||
var returnValue: Result<Void, SpaceServiceProxyError>? = nil
|
||||
DispatchQueue.main.sync {
|
||||
returnValue = removeChildFromUnderlyingReturnValue
|
||||
}
|
||||
|
||||
return returnValue!
|
||||
}
|
||||
}
|
||||
set {
|
||||
if Thread.isMainThread {
|
||||
removeChildFromUnderlyingReturnValue = newValue
|
||||
} else {
|
||||
DispatchQueue.main.sync {
|
||||
removeChildFromUnderlyingReturnValue = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var removeChildFromClosure: ((String, String) async -> Result<Void, SpaceServiceProxyError>)?
|
||||
|
||||
func removeChild(_ childID: String, from spaceID: String) async -> Result<Void, SpaceServiceProxyError> {
|
||||
removeChildFromCallsCount += 1
|
||||
removeChildFromReceivedArguments = (childID: childID, spaceID: spaceID)
|
||||
DispatchQueue.main.async {
|
||||
self.removeChildFromReceivedInvocations.append((childID: childID, spaceID: spaceID))
|
||||
}
|
||||
if let removeChildFromClosure = removeChildFromClosure {
|
||||
return await removeChildFromClosure(childID, spaceID)
|
||||
} else {
|
||||
return removeChildFromReturnValue
|
||||
}
|
||||
}
|
||||
}
|
||||
class SpaceServiceRoomMock: SpaceServiceRoomProtocol, @unchecked Sendable {
|
||||
var id: String {
|
||||
|
||||
@@ -39,6 +39,7 @@ extension SpaceServiceProxyMock {
|
||||
.success(configuration.topLevelSpaces.first { $0.id == spaceID })
|
||||
}
|
||||
addChildToReturnValue = .success(())
|
||||
removeChildFromReturnValue = .success(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,28 @@ extension View {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder func backportButtonStyleGlass() -> some View {
|
||||
if #available(iOS 26, *) {
|
||||
buttonStyle(.glass)
|
||||
} else {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder func backportButtonStyleGlassProminent() -> some View {
|
||||
if #available(iOS 26, *) {
|
||||
// `.glassProminent` breaks our preview tests so we need to disable it when running tests.
|
||||
// https://github.com/pointfreeco/swift-snapshot-testing/issues/1029#issuecomment-3366942138
|
||||
if ProcessInfo.isRunningTests {
|
||||
self
|
||||
} else {
|
||||
buttonStyle(.glassProminent)
|
||||
}
|
||||
} else {
|
||||
buttonStyle(.borderedProminent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension ToolbarContent {
|
||||
|
||||
@@ -16,10 +16,11 @@ struct ToolbarButton: View {
|
||||
|
||||
case cancel(title: String)
|
||||
case confirm(title: String)
|
||||
case destructive(title: String)
|
||||
|
||||
var title: String {
|
||||
switch self {
|
||||
case .cancel(let title), .confirm(let title):
|
||||
case .cancel(let title), .confirm(let title), .destructive(let title):
|
||||
title
|
||||
}
|
||||
}
|
||||
@@ -33,6 +34,9 @@ struct ToolbarButton: View {
|
||||
case .confirm:
|
||||
CompoundIcon(\.check)
|
||||
.foregroundStyle(.compound.iconOnSolidPrimary)
|
||||
case .destructive:
|
||||
CompoundIcon(\.delete)
|
||||
.foregroundStyle(.compound.iconOnSolidPrimary)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +46,8 @@ struct ToolbarButton: View {
|
||||
.compound.bgCanvasDefault
|
||||
case .confirm:
|
||||
.compound.bgAccentRest
|
||||
case .destructive:
|
||||
.compound.bgCriticalPrimary
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,27 +62,13 @@ struct ToolbarButton: View {
|
||||
.accessibilityLabel(role.title)
|
||||
}
|
||||
.tint(role.tint)
|
||||
.buttonStyleGlassProminent()
|
||||
.backportButtonStyleGlassProminent()
|
||||
} else {
|
||||
Button(role.title, action: action)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 26, *)
|
||||
private extension View {
|
||||
@ViewBuilder
|
||||
func buttonStyleGlassProminent() -> some View {
|
||||
// `.glassProminent` breaks our preview tests so we need to disable it when running tests.
|
||||
// https://github.com/pointfreeco/swift-snapshot-testing/issues/1029#issuecomment-3366942138
|
||||
if ProcessInfo.isRunningTests {
|
||||
self
|
||||
} else {
|
||||
buttonStyle(.glassProminent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ToolbarButton_Previews: PreviewProvider, TestablePreview {
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
@@ -88,6 +80,9 @@ struct ToolbarButton_Previews: PreviewProvider, TestablePreview {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
ToolbarButton(role: .cancel) { }
|
||||
}
|
||||
ToolbarItem(placement: .primaryAction) {
|
||||
ToolbarButton(role: .destructive(title: L10n.actionRemove)) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,6 +167,7 @@ enum TestablePreviewsDictionary {
|
||||
"SpaceAddRoomsScreen_Previews" : SpaceAddRoomsScreen_Previews.self,
|
||||
"SpaceHeaderTopicSheetView_Previews" : SpaceHeaderTopicSheetView_Previews.self,
|
||||
"SpaceHeaderView_Previews" : SpaceHeaderView_Previews.self,
|
||||
"SpaceRemoveChildrenConfirmationView_Previews" : SpaceRemoveChildrenConfirmationView_Previews.self,
|
||||
"SpaceRoomCell_Previews" : SpaceRoomCell_Previews.self,
|
||||
"SpaceScreen_Previews" : SpaceScreen_Previews.self,
|
||||
"SpaceSettingsScreen_Previews" : SpaceSettingsScreen_Previews.self,
|
||||
|
||||
@@ -11,7 +11,8 @@ import Compound
|
||||
import SwiftUI
|
||||
|
||||
struct SpaceRoomCell: View {
|
||||
@Environment(\.dynamicTypeSize) var dynamicTypeSize
|
||||
@Environment(\.dynamicTypeSize) private var dynamicTypeSize
|
||||
@Environment(\.editMode) private var editMode
|
||||
|
||||
let spaceServiceRoom: SpaceServiceRoomProtocol
|
||||
let isSelected: Bool
|
||||
@@ -24,6 +25,9 @@ struct SpaceRoomCell: View {
|
||||
private let verticalInsets = 12.0
|
||||
private let horizontalInsets = 16.0
|
||||
|
||||
private var isEditModeActive: Bool { editMode?.wrappedValue ?? .inactive != .inactive }
|
||||
private var isHighlighted: Bool { isSelected && !isEditModeActive }
|
||||
|
||||
private var subtitle: String {
|
||||
if spaceServiceRoom.isSpace {
|
||||
switch spaceServiceRoom.visibility {
|
||||
@@ -58,22 +62,34 @@ struct SpaceRoomCell: View {
|
||||
Button {
|
||||
action(.select(spaceServiceRoom))
|
||||
} label: {
|
||||
HStack(spacing: 16.0) {
|
||||
avatar
|
||||
|
||||
content
|
||||
.padding(.vertical, verticalInsets)
|
||||
.overlay(alignment: .bottom) {
|
||||
Rectangle()
|
||||
.fill(Color.compound.borderDisabled)
|
||||
.frame(height: 1 / UIScreen.main.scale)
|
||||
.padding(.trailing, -horizontalInsets)
|
||||
HStack(spacing: 0) {
|
||||
if isEditModeActive {
|
||||
ZStack {
|
||||
ListRowAccessory.multiSelection(isSelected)
|
||||
}
|
||||
// Use padding rather than spacing to improve the animation.
|
||||
.padding(.trailing, 16)
|
||||
// Put the transition on a ZStack to prevent it from being applied during selection/deselection.
|
||||
.transition(.move(edge: .leading).combined(with: .opacity))
|
||||
}
|
||||
|
||||
HStack(spacing: 16) {
|
||||
avatar
|
||||
|
||||
content
|
||||
.padding(.vertical, verticalInsets)
|
||||
.overlay(alignment: .bottom) {
|
||||
Rectangle()
|
||||
.fill(Color.compound.borderDisabled)
|
||||
.frame(height: 1 / UIScreen.main.scale)
|
||||
.padding(.trailing, -horizontalInsets)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, horizontalInsets)
|
||||
.accessibilityElement(children: .combine)
|
||||
}
|
||||
.buttonStyle(SpaceRoomCellButtonStyle(isSelected: isSelected))
|
||||
.buttonStyle(SpaceRoomCellButtonStyle(isHighlighted: isHighlighted))
|
||||
.accessibilityIdentifier(A11yIdentifiers.spacesScreen.spaceRoomName(spaceServiceRoom.name))
|
||||
}
|
||||
|
||||
@@ -146,13 +162,13 @@ struct SpaceRoomCell: View {
|
||||
}
|
||||
|
||||
struct SpaceRoomCellButtonStyle: ButtonStyle {
|
||||
let isSelected: Bool
|
||||
let isHighlighted: Bool
|
||||
|
||||
func makeBody(configuration: Configuration) -> some View {
|
||||
configuration.label
|
||||
.background(isSelected || configuration.isPressed ? Color.compound.bgSubtleSecondary : Color.compound.bgCanvasDefault)
|
||||
.background(isHighlighted || configuration.isPressed ? Color.compound.bgSubtleSecondary : Color.compound.bgCanvasDefault)
|
||||
.contentShape(Rectangle())
|
||||
.animation(isSelected ? .none : .easeOut(duration: 0.1).disabledDuringTests(), value: isSelected)
|
||||
.animation(isHighlighted ? .none : .easeOut(duration: 0.1).disabledDuringTests(), value: isHighlighted)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,21 +178,35 @@ struct SpaceRoomCell_Previews: PreviewProvider, TestablePreview {
|
||||
static let spaces = [SpaceServiceRoomProtocol].mockSpaceList
|
||||
|
||||
static var previews: some View {
|
||||
VStack(spacing: 0) {
|
||||
ForEach(spaces, id: \.id) { space in
|
||||
SpaceRoomCell(spaceServiceRoom: space,
|
||||
ScrollView {
|
||||
VStack(spacing: 0) {
|
||||
ForEach(spaces, id: \.id) { space in
|
||||
SpaceRoomCell(spaceServiceRoom: space,
|
||||
isSelected: false,
|
||||
mediaProvider: mediaProvider) { _ in }
|
||||
}
|
||||
|
||||
SpaceRoomCell(spaceServiceRoom: SpaceServiceRoomMock(.init(id: "Space being joined", isSpace: true)),
|
||||
isSelected: false,
|
||||
isJoining: true,
|
||||
mediaProvider: mediaProvider) { _ in }
|
||||
SpaceRoomCell(spaceServiceRoom: SpaceServiceRoomMock(.init(id: "Room being joined", isSpace: false)),
|
||||
isSelected: false,
|
||||
isJoining: true,
|
||||
mediaProvider: mediaProvider) { _ in }
|
||||
|
||||
SpaceRoomCell(spaceServiceRoom: SpaceServiceRoomMock(.init(id: "Selected", isSpace: false, state: .joined)),
|
||||
isSelected: true,
|
||||
isJoining: false,
|
||||
mediaProvider: mediaProvider) { _ in }
|
||||
.environment(\.editMode, .constant(.active))
|
||||
SpaceRoomCell(spaceServiceRoom: SpaceServiceRoomMock(.init(id: "Unselected", isSpace: false, state: .joined)),
|
||||
isSelected: false,
|
||||
isJoining: false,
|
||||
mediaProvider: mediaProvider) { _ in }
|
||||
.environment(\.editMode, .constant(.active))
|
||||
}
|
||||
|
||||
SpaceRoomCell(spaceServiceRoom: SpaceServiceRoomMock(.init(id: "Space being joined", isSpace: true)),
|
||||
isSelected: false,
|
||||
isJoining: true,
|
||||
mediaProvider: mediaProvider) { _ in }
|
||||
SpaceRoomCell(spaceServiceRoom: SpaceServiceRoomMock(.init(id: "Room being joined", isSpace: false)),
|
||||
isSelected: false,
|
||||
isJoining: true,
|
||||
mediaProvider: mediaProvider) { _ in }
|
||||
}
|
||||
.previewLayout(.fixed(width: 390, height: 850))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ struct LeaveSpaceRoomDetailsCell: View {
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
}
|
||||
.buttonStyle(SpaceRoomCellButtonStyle(isSelected: false))
|
||||
.buttonStyle(SpaceRoomCellButtonStyle(isHighlighted: false))
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
enum SpaceScreenViewModelAction {
|
||||
case selectSpace(SpaceRoomListProxyProtocol)
|
||||
@@ -33,14 +33,30 @@ struct SpaceScreenViewState: BindableState {
|
||||
var canEditRolesAndPermissions = false
|
||||
var canEditSecurityAndPrivacy = false
|
||||
|
||||
var editMode: EditMode = .inactive
|
||||
var editModeSelectedIDs: Set<String> = []
|
||||
|
||||
var bindings = SpaceScreenViewStateBindings()
|
||||
|
||||
var visibleRooms: [SpaceServiceRoomProtocol] {
|
||||
if editMode == .inactive {
|
||||
rooms
|
||||
} else {
|
||||
rooms.filter { !$0.isSpace }
|
||||
}
|
||||
}
|
||||
|
||||
var isSpaceManagementEnabled: Bool {
|
||||
canEditBaseInfo || canEditRolesAndPermissions || canEditSecurityAndPrivacy
|
||||
}
|
||||
|
||||
var bindings = SpaceScreenViewStateBindings()
|
||||
func isSpaceIDSelected(_ spaceID: String) -> Bool {
|
||||
selectedSpaceRoomID == spaceID || editModeSelectedIDs.contains(spaceID)
|
||||
}
|
||||
}
|
||||
|
||||
struct SpaceScreenViewStateBindings {
|
||||
var isPresentingRemoveChildrenConfirmation = false
|
||||
var leaveSpaceViewModel: LeaveSpaceViewModel?
|
||||
}
|
||||
|
||||
@@ -49,4 +65,8 @@ enum SpaceScreenViewAction {
|
||||
case leaveSpace
|
||||
case spaceSettings(roomProxy: JoinedRoomProxyProtocol)
|
||||
case displayMembers(roomProxy: JoinedRoomProxyProtocol)
|
||||
case manageChildren
|
||||
case removeSelectedChildren
|
||||
case confirmRemoveSelectedChildren
|
||||
case finishManagingChildren
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
|
||||
MXLog.info("View model: received view action: \(viewAction)")
|
||||
|
||||
switch viewAction {
|
||||
case .spaceAction(.select(let spaceServiceRoom)):
|
||||
case .spaceAction(.select(let spaceServiceRoom)) where state.editMode == .inactive:
|
||||
if spaceServiceRoom.isSpace {
|
||||
if spaceServiceRoom.state != .joined {
|
||||
actionsSubject.send(.selectUnjoinedSpace(spaceServiceRoom))
|
||||
@@ -118,6 +118,14 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
|
||||
// No need to check the join state, the room flow will show an appropriately configured join screen if needed.
|
||||
actionsSubject.send(.selectRoom(roomID: spaceServiceRoom.id))
|
||||
}
|
||||
case .spaceAction(.select(let spaceServiceRoom)): // isEditModeActive == true
|
||||
withTransaction(\.disablesAnimations, true) { // The button adds an unwanted animation.
|
||||
if state.editModeSelectedIDs.contains(spaceServiceRoom.id) {
|
||||
state.editModeSelectedIDs.remove(spaceServiceRoom.id)
|
||||
} else {
|
||||
state.editModeSelectedIDs.insert(spaceServiceRoom.id)
|
||||
}
|
||||
}
|
||||
case .spaceAction(.join(let spaceServiceRoom)):
|
||||
Task { await join(spaceServiceRoom) }
|
||||
case .leaveSpace:
|
||||
@@ -126,6 +134,20 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
|
||||
actionsSubject.send(.displayMembers(roomProxy: roomProxy))
|
||||
case .spaceSettings(let roomProxy):
|
||||
actionsSubject.send(.displaySpaceSettings(roomProxy: roomProxy))
|
||||
case .manageChildren:
|
||||
withAnimation(.easeOut(duration: 0.25).disabledDuringTests()) {
|
||||
state.editMode = .transient
|
||||
}
|
||||
case .removeSelectedChildren:
|
||||
state.bindings.isPresentingRemoveChildrenConfirmation = true
|
||||
case .confirmRemoveSelectedChildren:
|
||||
Task { await removeSelectedChildren() }
|
||||
case .finishManagingChildren:
|
||||
withAnimation(.easeOut(duration: 0.25).disabledDuringTests()) {
|
||||
state.editMode = .inactive
|
||||
} completion: {
|
||||
self.state.editModeSelectedIDs.removeAll()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,6 +180,25 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
|
||||
}
|
||||
}
|
||||
|
||||
private func removeSelectedChildren() async {
|
||||
showRemovingIndicator()
|
||||
defer { hideRemovingIndicator() }
|
||||
|
||||
state.bindings.isPresentingRemoveChildrenConfirmation = false
|
||||
|
||||
for childID in state.editModeSelectedIDs {
|
||||
switch await spaceServiceProxy.removeChild(childID, from: spaceRoomListProxy.id) {
|
||||
case .success:
|
||||
MXLog.info("Successfully removed \(childID) from \(spaceRoomListProxy.id)")
|
||||
case .failure:
|
||||
showFailureIndicator()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
process(viewAction: .finishManagingChildren)
|
||||
}
|
||||
|
||||
private func showLeaveSpaceConfirmation() async {
|
||||
guard case let .success(leaveHandle) = await spaceServiceProxy.leaveSpace(spaceID: spaceRoomListProxy.id) else {
|
||||
showFailureIndicator()
|
||||
@@ -192,9 +233,20 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
|
||||
|
||||
// MARK: - Indicators
|
||||
|
||||
private static var leavingIndicatorID: String { "\(Self.self)-Leaving" }
|
||||
private static var removingIndicatorID: String { "\(Self.self)-Removing" }
|
||||
private static var failureIndicatorID: String { "\(Self.self)-Failure" }
|
||||
|
||||
private func showRemovingIndicator() {
|
||||
userIndicatorController.submitIndicator(UserIndicator(id: Self.removingIndicatorID,
|
||||
type: .modal(progress: .indeterminate, interactiveDismissDisabled: true, allowsInteraction: false),
|
||||
title: L10n.commonRemoving,
|
||||
persistent: true))
|
||||
}
|
||||
|
||||
private func hideRemovingIndicator() {
|
||||
userIndicatorController.retractIndicatorWithId(Self.removingIndicatorID)
|
||||
}
|
||||
|
||||
private func showFailureIndicator() {
|
||||
userIndicatorController.submitIndicator(UserIndicator(id: Self.failureIndicatorID,
|
||||
type: .toast,
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// Copyright 2025 Element Creations Ltd.
|
||||
// Copyright 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 SpaceRemoveChildrenConfirmationView: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
let spaceName: String
|
||||
let action: () -> Void
|
||||
|
||||
@State private var scrollViewHeight: CGFloat = .zero
|
||||
@State private var buttonsHeight: CGFloat = .zero
|
||||
private let topPadding = 19.0
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
TitleAndIcon(title: L10n.screenSpaceRemoveRoomsConfirmationTitleIos(spaceName),
|
||||
subtitle: L10n.screenSpaceRemoveRoomsConfirmationContent,
|
||||
icon: \.errorSolid,
|
||||
iconStyle: .alertSolid)
|
||||
.padding(24)
|
||||
.readHeight($scrollViewHeight)
|
||||
}
|
||||
.backportSafeAreaBar(edge: .bottom, spacing: 0) {
|
||||
buttons
|
||||
.readHeight($buttonsHeight)
|
||||
}
|
||||
.scrollBounceBehavior(.basedOnSize)
|
||||
.padding(.top, topPadding) // For the drag indicator
|
||||
.presentationDetents([.height(scrollViewHeight + buttonsHeight + topPadding)])
|
||||
.presentationDragIndicator(.visible)
|
||||
.presentationBackground(.compound.bgCanvasDefault)
|
||||
}
|
||||
|
||||
var buttons: some View {
|
||||
VStack(spacing: 16) {
|
||||
Button(L10n.actionRemove, role: .destructive, action: action)
|
||||
.buttonStyle(.compound(.primary))
|
||||
|
||||
Button(L10n.actionCancel, action: dismiss.callAsFunction)
|
||||
.buttonStyle(.compound(.tertiary))
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.top, 16)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct SpaceRemoveChildrenConfirmationView_Previews: PreviewProvider, TestablePreview {
|
||||
static var previews: some View {
|
||||
SpaceRemoveChildrenConfirmationView(spaceName: "Company") { }
|
||||
}
|
||||
}
|
||||
@@ -12,19 +12,37 @@ import SwiftUI
|
||||
struct SpaceScreen: View {
|
||||
@Bindable var context: SpaceScreenViewModel.Context
|
||||
|
||||
private var isEditModeActive: Bool { context.viewState.editMode != .inactive }
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
LazyVStack(spacing: 0) {
|
||||
SpaceHeaderView(spaceServiceRoom: context.viewState.space,
|
||||
mediaProvider: context.mediaProvider)
|
||||
if !isEditModeActive {
|
||||
SpaceHeaderView(spaceServiceRoom: context.viewState.space,
|
||||
mediaProvider: context.mediaProvider)
|
||||
}
|
||||
|
||||
rooms
|
||||
}
|
||||
}
|
||||
.environment(\.editMode, .constant(context.viewState.editMode))
|
||||
.background(Color.compound.bgCanvasDefault.ignoresSafeArea())
|
||||
.toolbarRole(RoomHeaderView.toolbarRole)
|
||||
.toolbarRole(isEditModeActive ? .automatic : RoomHeaderView.toolbarRole)
|
||||
.navigationTitle(context.viewState.space.name)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar { toolbar }
|
||||
.navigationBarBackButtonHidden(isEditModeActive)
|
||||
.toolbar {
|
||||
if isEditModeActive {
|
||||
editModeToolbar
|
||||
} else {
|
||||
toolbar
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $context.isPresentingRemoveChildrenConfirmation) {
|
||||
SpaceRemoveChildrenConfirmationView(spaceName: context.viewState.space.name) {
|
||||
context.send(viewAction: .confirmRemoveSelectedChildren)
|
||||
}
|
||||
}
|
||||
.sheet(item: $context.leaveSpaceViewModel) { leaveSpaceViewModel in
|
||||
LeaveSpaceView(context: leaveSpaceViewModel.context)
|
||||
}
|
||||
@@ -32,9 +50,9 @@ struct SpaceScreen: View {
|
||||
|
||||
@ViewBuilder
|
||||
var rooms: some View {
|
||||
ForEach(context.viewState.rooms, id: \.id) { spaceServiceRoom in
|
||||
ForEach(context.viewState.visibleRooms, id: \.id) { spaceServiceRoom in
|
||||
SpaceRoomCell(spaceServiceRoom: spaceServiceRoom,
|
||||
isSelected: spaceServiceRoom.id == context.viewState.selectedSpaceRoomID,
|
||||
isSelected: context.viewState.isSpaceIDSelected(spaceServiceRoom.id),
|
||||
isJoining: context.viewState.joiningRoomIDs.contains(spaceServiceRoom.id),
|
||||
mediaProvider: context.mediaProvider) { action in
|
||||
context.send(viewAction: .spaceAction(action))
|
||||
@@ -100,20 +118,46 @@ struct SpaceScreen: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ToolbarContentBuilder
|
||||
var editModeToolbar: some ToolbarContent {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button(L10n.actionCancel, role: .cancel) {
|
||||
context.send(viewAction: .finishManagingChildren)
|
||||
}
|
||||
}
|
||||
|
||||
ToolbarItem(placement: .principal) {
|
||||
Text(L10n.commonSelectedCount(context.viewState.editModeSelectedIDs.count))
|
||||
}
|
||||
|
||||
ToolbarItem(placement: .primaryAction) {
|
||||
ToolbarButton(role: .destructive(title: L10n.actionRemove)) {
|
||||
context.send(viewAction: .removeSelectedChildren)
|
||||
}
|
||||
.disabled(context.viewState.editModeSelectedIDs.isEmpty)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct SpaceScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let viewModel = makeViewModel()
|
||||
static let managingViewModel = makeViewModel(isManagingRooms: true)
|
||||
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
SpaceScreen(context: viewModel.context)
|
||||
}
|
||||
|
||||
NavigationStack {
|
||||
SpaceScreen(context: managingViewModel.context)
|
||||
}
|
||||
.previewDisplayName("Managing")
|
||||
}
|
||||
|
||||
static func makeViewModel() -> SpaceScreenViewModel {
|
||||
static func makeViewModel(isManagingRooms: Bool = false) -> SpaceScreenViewModel {
|
||||
let spaceServiceRoom = SpaceServiceRoomMock(.init(id: "!eng-space:matrix.org",
|
||||
name: "Engineering Team",
|
||||
isSpace: true,
|
||||
@@ -138,6 +182,12 @@ struct SpaceScreen_Previews: PreviewProvider, TestablePreview {
|
||||
userSession: userSession,
|
||||
appSettings: AppSettings(),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
|
||||
if isManagingRooms {
|
||||
viewModel.state.editMode = .transient
|
||||
viewModel.state.editModeSelectedIDs = [viewModel.state.visibleRooms[0].id]
|
||||
}
|
||||
|
||||
return viewModel
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,15 @@ class SpaceServiceProxy: SpaceServiceProxyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
func removeChild(_ childID: String, from spaceID: String) async -> Result<Void, SpaceServiceProxyError> {
|
||||
do {
|
||||
return try await .success(spaceService.removeChildFromSpace(childId: childID, spaceId: spaceID))
|
||||
} catch {
|
||||
MXLog.error("Failed to remove child \(childID) to space \(spaceID)")
|
||||
return .failure(.sdkError(error))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func handleUpdates(_ updates: [SpaceListUpdate]) {
|
||||
|
||||
@@ -26,4 +26,5 @@ protocol SpaceServiceProxyProtocol {
|
||||
|
||||
/// Adds a room (or space) as a child of another space.
|
||||
func addChild(_ childID: String, to spaceID: String) async -> Result<Void, SpaceServiceProxyError>
|
||||
func removeChild(_ childID: String, from spaceID: String) async -> Result<Void, SpaceServiceProxyError>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user