refactor: To pass the ViewModel to coordinator
This commit is contained in:
parent
1411bcadf6
commit
21264fead1
@ -65,8 +65,8 @@ extension SceneCoordinator {
|
||||
case safari(url: URL)
|
||||
case alertController(alertController: UIAlertController)
|
||||
case activityViewController(activityViewController: UIActivityViewController, sourceView: UIView?, barButtonItem: UIBarButtonItem?)
|
||||
case settings
|
||||
case report(userId: String, statusId: String?)
|
||||
case settings(viewModel: SettingsViewModel)
|
||||
case report(viewModel: ReportViewModel)
|
||||
#if DEBUG
|
||||
case publicTimeline
|
||||
#endif
|
||||
@ -265,22 +265,13 @@ private extension SceneCoordinator {
|
||||
activityViewController.popoverPresentationController?.sourceView = sourceView
|
||||
activityViewController.popoverPresentationController?.barButtonItem = barButtonItem
|
||||
viewController = activityViewController
|
||||
case .settings:
|
||||
case .settings(let viewModel):
|
||||
let _viewController = SettingsViewController()
|
||||
_viewController.viewModel = SettingsViewModel(context: appContext, coordinator: self)
|
||||
_viewController.viewModel = viewModel
|
||||
viewController = _viewController
|
||||
case .report(let userId, let statusId):
|
||||
guard let authenticationBox = appContext.authenticationService.activeMastodonAuthenticationBox.value else {
|
||||
return nil
|
||||
}
|
||||
case .report(let viewModel):
|
||||
let _viewController = ReportViewController()
|
||||
_viewController.viewModel = ReportViewModel(
|
||||
context: appContext,
|
||||
coordinator: self,
|
||||
domain: authenticationBox.domain,
|
||||
userId: userId,
|
||||
statusId: statusId
|
||||
)
|
||||
_viewController.viewModel = viewModel
|
||||
viewController = _viewController
|
||||
#if DEBUG
|
||||
case .publicTimeline:
|
||||
|
@ -332,7 +332,12 @@ extension HomeTimelineViewController {
|
||||
}
|
||||
|
||||
@objc private func showSettings(_ sender: UIAction) {
|
||||
coordinator.present(scene: .settings, from: self, transition: .modal(animated: true, completion: nil))
|
||||
let viewModel = SettingsViewModel(context: context)
|
||||
coordinator.present(
|
||||
scene: .settings(viewModel: viewModel),
|
||||
from: self,
|
||||
transition: .modal(animated: true, completion: nil)
|
||||
)
|
||||
}
|
||||
|
||||
@objc private func showReportAction(_ sender: UIAction) {
|
||||
@ -350,12 +355,20 @@ extension HomeTimelineViewController {
|
||||
|
||||
guard let userId = accountTextField.text else { return }
|
||||
guard let statusId = statusTextField.text else { return }
|
||||
guard let authenticationBox = self.context.authenticationService.activeMastodonAuthenticationBox.value else { return }
|
||||
|
||||
// itodo: delete them
|
||||
// 31803
|
||||
// 106093402888557459
|
||||
let viewModel = ReportViewModel(
|
||||
context: self.context,
|
||||
coordinator: self.coordinator,
|
||||
domain: authenticationBox.domain,
|
||||
userId: userId,
|
||||
statusId: statusId
|
||||
)
|
||||
self.coordinator.present(
|
||||
scene: .report(userId: userId, statusId: statusId),
|
||||
scene: .report(viewModel: viewModel),
|
||||
from: self, transition: .modal(animated: true, completion: nil))
|
||||
}
|
||||
alertController.addAction(showAction)
|
||||
|
@ -13,10 +13,9 @@ import MastodonSDK
|
||||
import UIKit
|
||||
import os.log
|
||||
|
||||
class SettingsViewModel: NSObject, NeedsDependency {
|
||||
class SettingsViewModel: NSObject {
|
||||
// confirm set only once
|
||||
weak var context: AppContext! { willSet { precondition(context == nil) } }
|
||||
weak var coordinator: SceneCoordinator! { willSet { precondition(coordinator == nil) } }
|
||||
|
||||
var dataSource: UITableViewDiffableDataSource<SettingsSection, SettingsItem>!
|
||||
var disposeBag = Set<AnyCancellable>()
|
||||
@ -87,9 +86,8 @@ class SettingsViewModel: NSObject, NeedsDependency {
|
||||
struct Output {
|
||||
}
|
||||
|
||||
init(context: AppContext, coordinator: SceneCoordinator) {
|
||||
init(context: AppContext) {
|
||||
self.context = context
|
||||
self.coordinator = coordinator
|
||||
|
||||
super.init()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user