mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +00:00
Initial implementation of the JoinRoomScreen. (#2684)
* Update Compound and use super button for room directory.
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// 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))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user