mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Implement Knock Logic (#3573)
* WIP RequestToJoin struct * implemented the logic to display the cells * knock request banner accept flow * mark all knocks as seen implemented * details logic * implemented accept, decline and ban in the list * added a loader and modified the stacked view of the banner * pr suggestions * updated naming and loading strings * added the initial loading state improved code and the tests * updated a string that has changed * code improvement * tests for the room screen view model * room details tests and improved the knock requests tests for the room screen * knock requests list tests * added error state alerts with retry * struct has been renamed on the sdk so I renamed it also on the app side * update SDK
This commit is contained in:
+53
-16
@@ -17,12 +17,12 @@ struct KnockRequestsListScreen: View {
|
||||
.navigationTitle(L10n.screenKnockRequestsListTitle)
|
||||
.background(.compound.bgCanvasDefault)
|
||||
.overlay {
|
||||
if !context.viewState.shouldDisplayRequests {
|
||||
if context.viewState.shouldDisplayEmptyView {
|
||||
KnockRequestsListEmptyStateView()
|
||||
}
|
||||
}
|
||||
.safeAreaInset(edge: .bottom) {
|
||||
if context.viewState.shouldDisplayRequests {
|
||||
if context.viewState.shouldDisplayAcceptAllButton {
|
||||
acceptAllButton
|
||||
}
|
||||
}
|
||||
@@ -31,10 +31,18 @@ struct KnockRequestsListScreen: View {
|
||||
|
||||
@ViewBuilder
|
||||
private var mainContent: some View {
|
||||
if context.viewState.isLoading {
|
||||
EmptyView()
|
||||
} else {
|
||||
list
|
||||
}
|
||||
}
|
||||
|
||||
private var list: some View {
|
||||
ScrollView {
|
||||
LazyVStack(spacing: 0) {
|
||||
if context.viewState.shouldDisplayRequests {
|
||||
ForEach(context.viewState.requests) { requestInfo in
|
||||
ForEach(context.viewState.displayedRequests) { requestInfo in
|
||||
ListRow(kind: .custom {
|
||||
KnockRequestCell(cellInfo: requestInfo,
|
||||
mediaProvider: context.mediaProvider,
|
||||
@@ -60,37 +68,66 @@ struct KnockRequestsListScreen: View {
|
||||
.background(.compound.bgCanvasDefault)
|
||||
}
|
||||
|
||||
private func onAccept(userID: String) {
|
||||
context.send(viewAction: .acceptRequest(userID: userID))
|
||||
private func onAccept(eventID: String) {
|
||||
context.send(viewAction: .acceptRequest(eventID: eventID))
|
||||
}
|
||||
|
||||
private func onDecline(userID: String) {
|
||||
context.send(viewAction: .declineRequest(userID: userID))
|
||||
private func onDecline(eventID: String) {
|
||||
context.send(viewAction: .declineRequest(eventID: eventID))
|
||||
}
|
||||
|
||||
private func onDeclineAndBan(userID: String) {
|
||||
context.send(viewAction: .ban(userID: userID))
|
||||
private func onDeclineAndBan(eventID: String) {
|
||||
context.send(viewAction: .ban(eventID: eventID))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct KnockRequestsListScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let emptyViewModel = KnockRequestsListScreenViewModel.mockWithInitialState(.init(requests: []))
|
||||
static let loadingViewModel = KnockRequestsListScreenViewModel.mockWithRequestsState(.loading)
|
||||
|
||||
static let emptyViewModel = KnockRequestsListScreenViewModel.mockWithRequestsState(.loaded([]))
|
||||
|
||||
static let singleRequestViewModel = KnockRequestsListScreenViewModel.mockWithRequestsState(.loaded([KnockRequestProxyMock(.init(eventID: "1", userID: "@alice:matrix.org", displayName: "Alice", avatarURL: nil, timestamp: "Now", reason: "Hello"))]))
|
||||
|
||||
static let viewModel = KnockRequestsListScreenViewModel.mockWithRequestsState(.loaded([KnockRequestProxyMock(.init(eventID: "1", userID: "@alice:matrix.org", displayName: "Alice", avatarURL: nil, timestamp: "Now", reason: "Hello")),
|
||||
// swiftlint:disable:next line_length
|
||||
KnockRequestProxyMock(.init(eventID: "2", userID: "@bob:matrix.org", displayName: "Bob", avatarURL: nil, timestamp: "Now", reason: "Hello this one is a very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long reason")),
|
||||
KnockRequestProxyMock(.init(eventID: "3", userID: "@charlie:matrix.org", displayName: "Charlie", avatarURL: nil, timestamp: "Now", reason: nil)),
|
||||
KnockRequestProxyMock(.init(eventID: "4", userID: "@dan:matrix.org", displayName: "Dan", avatarURL: nil, timestamp: "Now", reason: "Hello! It's a me! Dan!"))]))
|
||||
|
||||
static let viewModel = KnockRequestsListScreenViewModel.mockWithInitialState(.init(requests: [.init(id: "@alice:matrix.org", displayName: "Alice", avatarURL: nil, timestamp: "Now", reason: "Hello"),
|
||||
// swiftlint:disable:next line_length
|
||||
.init(id: "@bob:matrix.org", displayName: "Bob", avatarURL: nil, timestamp: "Now", reason: "Hello this one is a very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long reason"),
|
||||
.init(id: "@charlie:matrix.org", displayName: "Charlie", avatarURL: nil, timestamp: "Now", reason: nil),
|
||||
.init(id: "@dan:matrix.org", displayName: "Dan", avatarURL: nil, timestamp: "Now", reason: "Hello! It's a me! Dan!")]))
|
||||
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
KnockRequestsListScreen(context: viewModel.context)
|
||||
}
|
||||
.snapshotPreferences(delay: 0.2)
|
||||
|
||||
NavigationStack {
|
||||
KnockRequestsListScreen(context: singleRequestViewModel.context)
|
||||
}
|
||||
.previewDisplayName("Single Request")
|
||||
.snapshotPreferences(delay: 0.2)
|
||||
|
||||
NavigationStack {
|
||||
KnockRequestsListScreen(context: emptyViewModel.context)
|
||||
}
|
||||
.previewDisplayName("Empty state")
|
||||
.snapshotPreferences(delay: 0.2)
|
||||
|
||||
NavigationStack {
|
||||
KnockRequestsListScreen(context: loadingViewModel.context)
|
||||
}
|
||||
.previewDisplayName("Loading state")
|
||||
}
|
||||
}
|
||||
|
||||
extension KnockRequestsListScreenViewModel {
|
||||
static func mockWithRequestsState(_ requestsState: KnockRequestsState) -> KnockRequestsListScreenViewModel {
|
||||
.init(roomProxy: JoinedRoomProxyMock(.init(members: [.mockAdmin],
|
||||
knockRequestsState: requestsState,
|
||||
ownUserID: RoomMemberProxyMock.mockAdmin.userID,
|
||||
joinRule: .knock)),
|
||||
mediaProvider: MediaProviderMock(),
|
||||
userIndicatorController: UserIndicatorControllerMock())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user