* Add poll attachment button * Add poll creation feature flag * Setup navigation to CreatePollScreen * Add create/cancel actions * Add create poll screen ui skeleton * Add bindings in CreatePollScreen * Add logics in CreatePollScreen * Cleanup code * Fix option deletion crash * Fix conflicts * Add create poll logic * Add localisations * Fix test build errors * Fix crash * Add UTs * Add accessibility IDs * Add ui tests * Add 240 char limit * Fix addOption hide behavior * Add maxNumberOfOptions * Cleanup code * Move delete workaround in the view model * Use compound delete icon
62 lines
2.1 KiB
Swift
62 lines
2.1 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 CreatePollScreenCoordinatorParameters { }
|
|
|
|
enum CreatePollScreenCoordinatorAction {
|
|
case cancel
|
|
case create(question: String, options: [String], pollKind: Poll.Kind)
|
|
}
|
|
|
|
final class CreatePollScreenCoordinator: CoordinatorProtocol {
|
|
private let parameters: CreatePollScreenCoordinatorParameters
|
|
private var viewModel: CreatePollScreenViewModelProtocol
|
|
private let actionsSubject: PassthroughSubject<CreatePollScreenCoordinatorAction, Never> = .init()
|
|
private var cancellables: Set<AnyCancellable> = .init()
|
|
|
|
var actions: AnyPublisher<CreatePollScreenCoordinatorAction, Never> {
|
|
actionsSubject.eraseToAnyPublisher()
|
|
}
|
|
|
|
init(parameters: CreatePollScreenCoordinatorParameters) {
|
|
self.parameters = parameters
|
|
|
|
viewModel = CreatePollScreenViewModel()
|
|
}
|
|
|
|
func start() {
|
|
viewModel.actions.sink { [weak self] action in
|
|
MXLog.info("Coordinator: received view model action: \(action)")
|
|
|
|
guard let self else { return }
|
|
switch action {
|
|
case let .create(question, options, pollKind):
|
|
self.actionsSubject.send(.create(question: question, options: options, pollKind: pollKind))
|
|
case .cancel:
|
|
self.actionsSubject.send(.cancel)
|
|
}
|
|
}
|
|
.store(in: &cancellables)
|
|
}
|
|
|
|
func toPresentable() -> AnyView {
|
|
AnyView(CreatePollScreen(context: viewModel.context))
|
|
}
|
|
}
|