diff --git a/ElementX/Sources/Mocks/RoomPreviewProxyMock.swift b/ElementX/Sources/Mocks/RoomPreviewProxyMock.swift index f59aa46e2e..547b427c6b 100644 --- a/ElementX/Sources/Mocks/RoomPreviewProxyMock.swift +++ b/ElementX/Sources/Mocks/RoomPreviewProxyMock.swift @@ -8,20 +8,20 @@ import Foundation import MatrixRustSDK -struct RoomPreviewProxyMockConfiguration { - var roomId = "1" - var canonicalAlias = "#3🌞problem:matrix.org" - var name = "The Three-Body Problem - 三体" - var topic = "“Science and technology were the only keys to opening the door to the future, and people approached science with the faith and sincerity of elementary school students.”" - var avatarUrl = URL.mockMXCAvatar.absoluteString - var numJoinedMembers = UInt64(100) - var numActiveMembers = UInt64(100) - var roomType = RoomType.room - var membership: Membership? - var joinRule: JoinRule -} - extension RoomPreviewProxyMock { + struct Configuration { + var roomID = "1" + var canonicalAlias = "#3🌞problem:matrix.org" + var name = "The Three-Body Problem - 三体" + var topic = "“Science and technology were the only keys to opening the door to the future, and people approached science with the faith and sincerity of elementary school students.”" + var avatarURL = URL.mockMXCAvatar.absoluteString + var numJoinedMembers = UInt64(100) + var numActiveMembers = UInt64(100) + var roomType = RoomType.room + var membership: Membership? + var joinRule: JoinRule + } + static var joinable: RoomPreviewProxyMock { .init(.init(membership: nil, joinRule: .public)) } @@ -36,7 +36,7 @@ extension RoomPreviewProxyMock { static func invited(roomID: String? = nil) -> RoomPreviewProxyMock { if let roomID { - return .init(.init(roomId: roomID, membership: .invited, joinRule: .invite)) + return .init(.init(roomID: roomID, membership: .invited, joinRule: .invite)) } return .init(.init(membership: .invited, joinRule: .invite)) @@ -58,13 +58,13 @@ extension RoomPreviewProxyMock { .init(.init(membership: .banned, joinRule: .public)) } - convenience init(_ configuration: RoomPreviewProxyMockConfiguration) { + convenience init(_ configuration: RoomPreviewProxyMock.Configuration) { self.init() - underlyingInfo = .init(roomPreviewInfo: .init(roomId: configuration.roomId, + underlyingInfo = .init(roomPreviewInfo: .init(roomId: configuration.roomID, canonicalAlias: configuration.canonicalAlias, name: configuration.name, topic: configuration.topic, - avatarUrl: configuration.avatarUrl, + avatarUrl: configuration.avatarURL, numJoinedMembers: configuration.numJoinedMembers, numActiveMembers: configuration.numActiveMembers, roomType: configuration.roomType, diff --git a/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenViewModel.swift b/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenViewModel.swift index f213c8020a..27a3fe8fdd 100644 --- a/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenViewModel.swift +++ b/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenViewModel.swift @@ -116,12 +116,12 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo break } - let name = roomInfo?.displayName ?? roomPreview?.info.displayName - state.roomDetails = JoinRoomScreenRoomDetails(name: name, - topic: roomInfo?.topic ?? roomPreview?.info.topic, - canonicalAlias: roomInfo?.canonicalAlias ?? roomPreview?.info.canonicalAlias, - avatar: roomInfo?.avatar ?? .room(id: roomID, name: name ?? "", avatarURL: roomPreview?.info.avatarURL), - memberCount: UInt(roomInfo?.activeMembersCount ?? Int(roomPreview?.info.activeMembersCount ?? 0)), + let info = roomInfo ?? roomPreview?.info + state.roomDetails = JoinRoomScreenRoomDetails(name: info?.displayName, + topic: info?.topic, + canonicalAlias: info?.canonicalAlias, + avatar: info?.avatar ?? .room(id: roomID, name: info?.displayName ?? "", avatarURL: nil), + memberCount: UInt(info?.activeMembersCount ?? 0), inviter: inviter) await updateMode() @@ -149,9 +149,7 @@ class JoinRoomScreenViewModel: JoinRoomScreenViewModelType, JoinRoomScreenViewMo case .private, .invite: state.mode = .inviteRequired case .knock, .knockRestricted: - if appSettings.knockingEnabled { - state.mode = .knockable - } + state.mode = appSettings.knockingEnabled ? .knockable : .joinable case .restricted: state.mode = .restricted default: diff --git a/ElementX/Sources/Screens/JoinRoomScreen/View/JoinRoomScreen.swift b/ElementX/Sources/Screens/JoinRoomScreen/View/JoinRoomScreen.swift index 73c3983748..bf912d525a 100644 --- a/ElementX/Sources/Screens/JoinRoomScreen/View/JoinRoomScreen.swift +++ b/ElementX/Sources/Screens/JoinRoomScreen/View/JoinRoomScreen.swift @@ -184,25 +184,18 @@ struct JoinRoomScreen: View { } func bottomNoticeMessage(_ notice: String) -> some View { - HStack(alignment: .top, spacing: 12) { - CompoundIcon(\.info) - - Text(notice) - .font(.compound.bodyLGSemibold) - .foregroundStyle(.compound.textPrimary) - - Spacer() - } - .padding() - .background(.compound.bgSubtleSecondary) - .cornerRadius(14, corners: .allCorners) + Label(notice, icon: \.info) + .labelStyle(.custom(spacing: 12, alignment: .top)) + .font(.compound.bodyLGSemibold) + .foregroundStyle(.compound.textPrimary) + .frame(maxWidth: .infinity, alignment: .leading) + .padding() + .background(.compound.bgSubtleSecondary) + .cornerRadius(14, corners: .allCorners) } func bottomErrorMessage(title: String, subtitle: String?) -> some View { - HStack(alignment: .top, spacing: 12) { - CompoundIcon(\.error) - .foregroundStyle(.compound.iconCriticalPrimary) - + Label { VStack(alignment: .leading, spacing: 4) { Text(title) .font(.compound.bodyLGSemibold) @@ -214,9 +207,12 @@ struct JoinRoomScreen: View { .foregroundStyle(.compound.textSecondary) } } - - Spacer() + } icon: { + CompoundIcon(\.error) + .foregroundStyle(.compound.iconCriticalPrimary) } + .labelStyle(.custom(spacing: 12, alignment: .top)) + .frame(maxWidth: .infinity, alignment: .leading) .padding() .background(.compound.bgSubtleSecondary) .cornerRadius(14, corners: .allCorners)