From 2bfd64e8900c158b4d6bf7442818912f30293903 Mon Sep 17 00:00:00 2001 From: Mauro Romito Date: Thu, 5 Dec 2024 11:58:44 +0100 Subject: [PATCH] added a loader and modified the stacked view of the banner --- .../KnockRequestsListScreenViewModel.swift | 24 +++++++++++++++++++ .../View/KnockRequestsBannerView.swift | 9 ++++--- ...annerView-iPad-en-GB.Multiple-Requests.png | 4 ++-- ...nnerView-iPad-pseudo.Multiple-Requests.png | 4 ++-- ...View-iPhone-16-en-GB.Multiple-Requests.png | 4 ++-- ...iew-iPhone-16-pseudo.Multiple-Requests.png | 4 ++-- ...nockRequestsListScreenViewModelTests.swift | 4 +++- 7 files changed, 41 insertions(+), 12 deletions(-) diff --git a/ElementX/Sources/Screens/KnockRequestsListScreen/KnockRequestsListScreenViewModel.swift b/ElementX/Sources/Screens/KnockRequestsListScreen/KnockRequestsListScreenViewModel.swift index 2160d50cfa..22eac22c05 100644 --- a/ElementX/Sources/Screens/KnockRequestsListScreen/KnockRequestsListScreenViewModel.swift +++ b/ElementX/Sources/Screens/KnockRequestsListScreen/KnockRequestsListScreenViewModel.swift @@ -77,6 +77,8 @@ class KnockRequestsListScreenViewModel: KnockRequestsListScreenViewModelType, Kn guard let request = roomProxy.requestsToJoinPublisher.value.first(where: { $0.eventID == eventID }) else { return } + showLoadingIndicator() + defer { hideLoadingIndicator() } state.handledEventIDs.insert(eventID) Task { switch await request.accept() { @@ -90,6 +92,8 @@ class KnockRequestsListScreenViewModel: KnockRequestsListScreenViewModelType, Kn } private func decline(request: RequestToJoinProxyProtocol) { + showLoadingIndicator() + defer { hideLoadingIndicator() } let eventID = request.eventID state.handledEventIDs.insert(eventID) Task { @@ -104,6 +108,8 @@ class KnockRequestsListScreenViewModel: KnockRequestsListScreenViewModelType, Kn } private func declineAndBan(request: RequestToJoinProxyProtocol) { + showLoadingIndicator() + defer { hideLoadingIndicator() } let eventID = request.eventID state.handledEventIDs.insert(eventID) Task { @@ -118,6 +124,8 @@ class KnockRequestsListScreenViewModel: KnockRequestsListScreenViewModelType, Kn } private func acceptAll() { + showLoadingIndicator() + defer { hideLoadingIndicator() } let requests = roomProxy.requestsToJoinPublisher.value state.handledEventIDs.formUnion(Set(requests.map(\.eventID))) Task { @@ -170,6 +178,22 @@ class KnockRequestsListScreenViewModel: KnockRequestsListScreenViewModelType, Kn state.canBan = await (try? roomProxy.canUserBan(userID: roomProxy.ownUserID).get()) == true } + private static let loadingIndicatorIdentifier = "\(KnockRequestsListScreenViewModel.self)-Loading" + + private func showLoadingIndicator() { + userIndicatorController.submitIndicator(UserIndicator(id: Self.loadingIndicatorIdentifier, + type: .modal(progress: .indeterminate, + interactiveDismissDisabled: false, + allowsInteraction: false), + title: L10n.commonLoading, + persistent: true), + delay: .seconds(0.25)) + } + + private func hideLoadingIndicator() { + userIndicatorController.retractIndicatorWithId(Self.loadingIndicatorIdentifier) + } + // For testing purposes private init(initialViewState: KnockRequestsListScreenViewState) { roomProxy = JoinedRoomProxyMock(.init()) diff --git a/ElementX/Sources/Screens/RoomScreen/View/KnockRequestsBannerView.swift b/ElementX/Sources/Screens/RoomScreen/View/KnockRequestsBannerView.swift index da49ccb1c8..a96b1cc9c3 100644 --- a/ElementX/Sources/Screens/RoomScreen/View/KnockRequestsBannerView.swift +++ b/ElementX/Sources/Screens/RoomScreen/View/KnockRequestsBannerView.swift @@ -124,7 +124,6 @@ private struct MultipleKnockRequestsBannerContent: View { requests .prefix(3) .map { .init(url: $0.avatarURL, name: $0.displayName, contentID: $0.userID) } - .reversed() } private var multipleKnockRequestsTitle: String { @@ -139,7 +138,7 @@ private struct MultipleKnockRequestsBannerContent: View { var body: some View { VStack(spacing: 14) { HStack(spacing: 10) { - StackedAvatarsView(overlap: 16, lineWidth: 2, shouldStackFromLast: true, avatars: avatars, avatarSize: .user(on: .knockingUsersBannerStack), mediaProvider: mediaProvider) + StackedAvatarsView(overlap: 16, lineWidth: 2, avatars: avatars, avatarSize: .user(on: .knockingUsersBannerStack), mediaProvider: mediaProvider) HStack(alignment: .top, spacing: 0) { Text(multipleKnockRequestsTitle) .lineLimit(2) @@ -176,7 +175,11 @@ private struct KnockRequestsBannerDismissButton: View { struct KnockRequestsBannerView_Previews: PreviewProvider, TestablePreview { static let singleRequest: [KnockRequestInfo] = [.init(displayName: "Alice", avatarURL: nil, userID: "@alice:matrix.org", reason: nil, eventID: "1")] - static let singleRequestWithReason: [KnockRequestInfo] = [.init(displayName: "Alice", avatarURL: nil, userID: "@alice:matrix.org", reason: "Hey, I’d like to join this room because of xyz topic and I’d like to participate in the room.", eventID: "1")] + static let singleRequestWithReason: [KnockRequestInfo] = [.init(displayName: "Alice", + avatarURL: nil, + userID: "@alice:matrix.org", + reason: "Hey, I’d like to join this room because of xyz topic and I’d like to participate in the room.", + eventID: "1")] static let singleRequestNoDisplayName: [KnockRequestInfo] = [.init(displayName: nil, avatarURL: nil, userID: "@alice:matrix.org", reason: nil, eventID: "1")] diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/test_knockRequestsBannerView-iPad-en-GB.Multiple-Requests.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/test_knockRequestsBannerView-iPad-en-GB.Multiple-Requests.png index a8d96c2b2a..434c0ac06c 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/test_knockRequestsBannerView-iPad-en-GB.Multiple-Requests.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/test_knockRequestsBannerView-iPad-en-GB.Multiple-Requests.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3879eccedadd6ef4dd6ae91070a0271b0fa064c025614933d0ac364ded809340 -size 91991 +oid sha256:cfccc8cc6f248c09748e20cfdf5cb663dccb783b5c4af1eee7e73e925c282a10 +size 92265 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/test_knockRequestsBannerView-iPad-pseudo.Multiple-Requests.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/test_knockRequestsBannerView-iPad-pseudo.Multiple-Requests.png index cf3f2802c9..e3a7fe95d0 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/test_knockRequestsBannerView-iPad-pseudo.Multiple-Requests.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/test_knockRequestsBannerView-iPad-pseudo.Multiple-Requests.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:494a4003821e6bdad2cafeaf1d3403de5801450a268b1a444fa227b3f04ecff9 -size 92830 +oid sha256:b774a8180dd03f6b1d99132c2e240a454ba27d7d562ea18f1fdf5edcc8eccdeb +size 93111 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/test_knockRequestsBannerView-iPhone-16-en-GB.Multiple-Requests.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/test_knockRequestsBannerView-iPhone-16-en-GB.Multiple-Requests.png index 7327e9bc9e..ec225234ce 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/test_knockRequestsBannerView-iPhone-16-en-GB.Multiple-Requests.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/test_knockRequestsBannerView-iPhone-16-en-GB.Multiple-Requests.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:415af5d4976c78a0ea3d69441cf77498d3c2412592c8c4c920105bc1f5e0805d -size 50054 +oid sha256:5d6532b2e58457f3c6534634134680e2c2365752f3da94dc236f76da3e905cb0 +size 50411 diff --git a/PreviewTests/Sources/__Snapshots__/PreviewTests/test_knockRequestsBannerView-iPhone-16-pseudo.Multiple-Requests.png b/PreviewTests/Sources/__Snapshots__/PreviewTests/test_knockRequestsBannerView-iPhone-16-pseudo.Multiple-Requests.png index 71e1663a3d..5215088fd7 100644 --- a/PreviewTests/Sources/__Snapshots__/PreviewTests/test_knockRequestsBannerView-iPhone-16-pseudo.Multiple-Requests.png +++ b/PreviewTests/Sources/__Snapshots__/PreviewTests/test_knockRequestsBannerView-iPhone-16-pseudo.Multiple-Requests.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:69c9eb6ef65eb92d7270002ceaa4a4e3d2326980c8656b6a5ea34f3c3cc62e98 -size 49455 +oid sha256:bbc7b975d03869322a908426a86dba2d8c3e6601bc56cc5ae41c3725288e1228 +size 49774 diff --git a/UnitTests/Sources/KnockRequestsListScreenViewModelTests.swift b/UnitTests/Sources/KnockRequestsListScreenViewModelTests.swift index fba35e93f7..b8752214c0 100644 --- a/UnitTests/Sources/KnockRequestsListScreenViewModelTests.swift +++ b/UnitTests/Sources/KnockRequestsListScreenViewModelTests.swift @@ -18,6 +18,8 @@ class KnockRequestsListScreenViewModelTests: XCTestCase { } override func setUpWithError() throws { - viewModel = KnockRequestsListScreenViewModel(roomProxy: JoinedRoomProxyMock(.init()), mediaProvider: MediaProviderMock()) + viewModel = KnockRequestsListScreenViewModel(roomProxy: JoinedRoomProxyMock(.init()), + mediaProvider: MediaProviderMock(), + userIndicatorController: UserIndicatorControllerMock()) } }