Files
element-x-ios/ElementX/Sources/Screens/SearchScreen/SearchScreenCoordinator.swift
T
Stefan Ceriu 02d9ed1f0e Address search PR review comments
- Drop the redundant searchService coordinator/view model parameter; derive it from the client proxy.
- Rename the globalSearch avatar size to search.
- Lift the query observation streams out of their tasks.
- Restore the appeared and updateVisibleRange comments.
- Use CompoundIcon defaults and a scaledFrame for media previews.
- Simplify the result mapping with compactMap(makeResult) and drop unsupported events by returning nil.
- Move the preview helpers beneath the previews.
2026-07-03 13:39:45 +03:00

55 lines
1.8 KiB
Swift

//
// Copyright 2026 Element Creations Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Combine
import SwiftUI
struct SearchScreenCoordinatorParameters {
let roomSummaryProvider: RoomSummaryProviderProtocol
let clientProxy: ClientProxyProtocol
let mediaProvider: MediaProviderProtocol
}
enum SearchScreenCoordinatorAction {
case presentRoom(roomID: String, eventID: String?)
case cancel
}
final class SearchScreenCoordinator: CoordinatorProtocol {
private let viewModel: SearchScreenViewModelProtocol
private var cancellables = Set<AnyCancellable>()
private let actionsSubject: PassthroughSubject<SearchScreenCoordinatorAction, Never> = .init()
var actionsPublisher: AnyPublisher<SearchScreenCoordinatorAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(parameters: SearchScreenCoordinatorParameters) {
viewModel = SearchScreenViewModel(roomSummaryProvider: parameters.roomSummaryProvider,
clientProxy: parameters.clientProxy,
mediaProvider: parameters.mediaProvider)
}
func start() {
viewModel.actionsPublisher.sink { [weak self] action in
guard let self else { return }
switch action {
case .presentRoom(let roomID, let eventID):
actionsSubject.send(.presentRoom(roomID: roomID, eventID: eventID))
case .cancel:
actionsSubject.send(.cancel)
}
}
.store(in: &cancellables)
}
func toPresentable() -> AnyView {
AnyView(SearchScreen(context: viewModel.context))
}
}