Files
element-x-ios/ElementX/Sources/Screens/JoinRoomScreen/JoinRoomScreenCoordinator.swift
T
Doug f8920d4d11 Initial implementation of the JoinRoomScreen. (#2684)
* Update Compound and use super button for room directory.
2024-04-12 13:13:22 +01:00

73 lines
2.4 KiB
Swift

//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Combine
import SwiftUI
struct JoinRoomScreenCoordinatorParameters {
let roomID: String
let roomName: String
let avatarURL: URL?
let interaction: JoinRoomScreenInteraction
let clientProxy: ClientProxyProtocol
}
enum JoinRoomScreenCoordinatorAction {
case joined
case cancelled
}
final class JoinRoomScreenCoordinator: CoordinatorProtocol {
private let parameters: JoinRoomScreenCoordinatorParameters
private let viewModel: JoinRoomScreenViewModelProtocol
private var cancellables = Set<AnyCancellable>()
private let actionsSubject: PassthroughSubject<JoinRoomScreenCoordinatorAction, Never> = .init()
var actionsPublisher: AnyPublisher<JoinRoomScreenCoordinatorAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(parameters: JoinRoomScreenCoordinatorParameters) {
self.parameters = parameters
viewModel = JoinRoomScreenViewModel(roomID: parameters.roomID,
roomName: parameters.roomName,
avatarURL: parameters.avatarURL,
interaction: parameters.interaction,
clientProxy: parameters.clientProxy)
}
func start() {
viewModel.actionsPublisher.sink { [weak self] action in
MXLog.info("Coordinator: received view model action: \(action)")
guard let self else { return }
switch action {
case .joined:
actionsSubject.send(.joined)
case .cancelled:
actionsSubject.send(.cancelled)
}
}
.store(in: &cancellables)
}
func toPresentable() -> AnyView {
AnyView(JoinRoomScreen(context: viewModel.context))
}
}