Space flow improvements. (#4430)

* Space flow improvements

- Use a state machine to select a space.
- Add a SpaceFlowCoordinator for recursively presenting subspaces.
- Get the spaceRoomListProxy when tapping on the space so we can indicate failures.
- Fix the total room count in SpaceListScreen.

* Refactor spaceRoom → spaceRoomProxy.

* Add a UI test for the Spaces flow.
This commit is contained in:
Doug
2025-08-22 15:49:47 +01:00
committed by GitHub
parent bb5deb9c50
commit d119964d50
34 changed files with 503 additions and 73 deletions
@@ -12,11 +12,13 @@ import SwiftUI
struct SpaceScreenCoordinatorParameters {
let spaceRoomListProxy: SpaceRoomListProxyProtocol
let spaceServiceProxy: SpaceServiceProxyProtocol
let mediaProvider: MediaProviderProtocol
let userIndicatorController: UserIndicatorControllerProtocol
}
enum SpaceScreenCoordinatorAction {
case selectSpace(SpaceRoomProxyProtocol)
case selectSpace(SpaceRoomListProxyProtocol)
}
final class SpaceScreenCoordinator: CoordinatorProtocol {
@@ -33,7 +35,10 @@ final class SpaceScreenCoordinator: CoordinatorProtocol {
init(parameters: SpaceScreenCoordinatorParameters) {
self.parameters = parameters
viewModel = SpaceScreenViewModel(spaceRoomList: parameters.spaceRoomListProxy, mediaProvider: parameters.mediaProvider)
viewModel = SpaceScreenViewModel(spaceRoomList: parameters.spaceRoomListProxy,
spaceServiceProxy: parameters.spaceServiceProxy,
mediaProvider: parameters.mediaProvider,
userIndicatorController: parameters.userIndicatorController)
}
func start() {
@@ -42,8 +47,8 @@ final class SpaceScreenCoordinator: CoordinatorProtocol {
guard let self else { return }
switch action {
case .selectSpace(let spaceRoom):
actionsSubject.send(.selectSpace(spaceRoom))
case .selectSpace(let spaceRoomListProxy):
actionsSubject.send(.selectSpace(spaceRoomListProxy))
}
}
.store(in: &cancellables)
@@ -8,7 +8,7 @@
import Foundation
enum SpaceScreenViewModelAction {
case selectSpace(SpaceRoomProxyProtocol)
case selectSpace(SpaceRoomListProxyProtocol)
}
struct SpaceScreenViewState: BindableState {
@@ -11,12 +11,21 @@ import SwiftUI
typealias SpaceScreenViewModelType = StateStoreViewModelV2<SpaceScreenViewState, SpaceScreenViewAction>
class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtocol {
private let spaceServiceProxy: SpaceServiceProxyProtocol
private let userIndicatorController: UserIndicatorControllerProtocol
private let actionsSubject: PassthroughSubject<SpaceScreenViewModelAction, Never> = .init()
var actionsPublisher: AnyPublisher<SpaceScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(spaceRoomList: SpaceRoomListProxyProtocol, mediaProvider: MediaProviderProtocol) {
init(spaceRoomList: SpaceRoomListProxyProtocol,
spaceServiceProxy: SpaceServiceProxyProtocol,
mediaProvider: MediaProviderProtocol,
userIndicatorController: UserIndicatorControllerProtocol) {
self.spaceServiceProxy = spaceServiceProxy
self.userIndicatorController = userIndicatorController
super.init(initialViewState: SpaceScreenViewState(space: spaceRoomList.spaceRoom,
rooms: spaceRoomList.spaceRoomsPublisher.value),
mediaProvider: mediaProvider)
@@ -47,14 +56,37 @@ class SpaceScreenViewModel: SpaceScreenViewModelType, SpaceScreenViewModelProtoc
MXLog.info("View model: received view action: \(viewAction)")
switch viewAction {
case .spaceAction(.select(let spaceRoom)):
if spaceRoom.isSpace {
actionsSubject.send(.selectSpace(spaceRoom))
case .spaceAction(.select(let spaceRoomProxy)):
if spaceRoomProxy.isSpace {
Task { await selectSpace(spaceRoomProxy) }
} else {
#warning("Implement joining")
#warning("Implement room flow")
}
case .spaceAction(.join(let spaceID)):
#warning("Implement joining.")
}
}
// MARK: - Private
private func selectSpace(_ spaceRoomProxy: SpaceRoomProxyProtocol) async {
switch await spaceServiceProxy.spaceRoomList(for: spaceRoomProxy) {
case .success(let spaceRoomListProxy):
actionsSubject.send(.selectSpace(spaceRoomListProxy))
case .failure(let error):
MXLog.error("Unable to select space: \(error)")
showFailureIndicator()
}
}
// MARK: - Indicators
private static var failureIndicatorID: String { "\(Self.self)-Failure" }
private func showFailureIndicator() {
userIndicatorController.submitIndicator(UserIndicator(id: Self.failureIndicatorID,
type: .toast,
title: L10n.errorUnknown,
iconName: "xmark"))
}
}
@@ -26,8 +26,8 @@ struct SpaceScreen: View {
@ViewBuilder
var rooms: some View {
ForEach(context.viewState.rooms, id: \.id) { spaceRoom in
SpaceRoomCell(spaceRoom: spaceRoom,
ForEach(context.viewState.rooms, id: \.id) { spaceRoomProxy in
SpaceRoomCell(spaceRoomProxy: spaceRoomProxy,
isSelected: false,
mediaProvider: context.mediaProvider) { action in
context.send(viewAction: .spaceAction(action))
@@ -65,7 +65,9 @@ struct SpaceScreen_Previews: PreviewProvider, TestablePreview {
initialSpaceRooms: .mockSpaceList))
let viewModel = SpaceScreenViewModel(spaceRoomList: spaceRoomListProxy,
mediaProvider: MediaProviderMock(configuration: .init()))
spaceServiceProxy: SpaceServiceProxyMock(.init()),
mediaProvider: MediaProviderMock(configuration: .init()),
userIndicatorController: UserIndicatorControllerMock())
return viewModel
}
}