Skip to content

Commit

Permalink
added a loader and modified the stacked view
Browse files Browse the repository at this point in the history
of the banner
  • Loading branch information
Velin92 committed Dec 5, 2024
1 parent d5921d1 commit 2bfd64e
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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")]

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

0 comments on commit 2bfd64e

Please sign in to comment.