|
| 1 | +import UIKit |
| 2 | +import Presentation |
| 3 | +import Swinject |
| 4 | +import RxFlow |
| 5 | +import Core |
| 6 | + |
| 7 | +public final class WinterInternFlow: Flow { |
| 8 | + public let container: Container |
| 9 | + private let rootViewController: WinterInternViewController |
| 10 | + public var root: Presentable { |
| 11 | + return rootViewController |
| 12 | + } |
| 13 | + |
| 14 | + public init(container: Container) { |
| 15 | + self.container = container |
| 16 | + self.rootViewController = container.resolve(WinterInternViewController.self)! |
| 17 | + } |
| 18 | + |
| 19 | + public func navigate(to step: Step) -> FlowContributors { |
| 20 | + guard let step = step as? RecruitmentStep else { return .none } |
| 21 | + |
| 22 | + switch step { |
| 23 | + case .recruitmentIsRequired: |
| 24 | + return navigateToRecruitment() |
| 25 | + |
| 26 | + case let .recruitmentDetailIsRequired(id): |
| 27 | + return navigateToRecruitmentDetail(recruitmentID: id) |
| 28 | + |
| 29 | + case .recruitmentFilterIsRequired: |
| 30 | + return navigateToRecruitmentFilter() |
| 31 | + |
| 32 | + case .searchRecruitmentIsRequired: |
| 33 | + return navigateToSearchRecruitment() |
| 34 | + } |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +private extension WinterInternFlow { |
| 39 | + func navigateToRecruitment() -> FlowContributors { |
| 40 | + return .one(flowContributor: .contribute( |
| 41 | + withNextPresentable: rootViewController, |
| 42 | + withNextStepper: rootViewController.viewModel |
| 43 | + )) |
| 44 | + } |
| 45 | + |
| 46 | + func navigateToRecruitmentDetail(recruitmentID: Int) -> FlowContributors { |
| 47 | + let recruitmentDetailFlow = RecruitmentDetailFlow(container: container) |
| 48 | + |
| 49 | + Flows.use(recruitmentDetailFlow, when: .created) { (root) in |
| 50 | + let view = root as? RecruitmentDetailViewController |
| 51 | + view?.viewModel.recruitmentID = recruitmentID |
| 52 | + view?.isPopViewController = { id, bookmark in |
| 53 | + let popView = self.rootViewController |
| 54 | + var oldData = popView.viewModel.recruitmentData.value |
| 55 | + oldData.enumerated().forEach { |
| 56 | + if $0.element.recruitID == id { |
| 57 | + oldData[$0.offset].bookmarked = bookmark |
| 58 | + } |
| 59 | + } |
| 60 | + popView.viewModel.recruitmentData.accept(oldData) |
| 61 | + popView.isTabNavigation = false |
| 62 | + } |
| 63 | + self.rootViewController.navigationController?.pushViewController( |
| 64 | + view!, animated: true |
| 65 | + ) |
| 66 | + } |
| 67 | + |
| 68 | + return .one(flowContributor: .contribute( |
| 69 | + withNextPresentable: recruitmentDetailFlow, |
| 70 | + withNextStepper: OneStepper(withSingleStep: RecruitmentDetailStep.recruitmentDetailIsRequired) |
| 71 | + )) |
| 72 | + } |
| 73 | + |
| 74 | + func navigateToSearchRecruitment() -> FlowContributors { |
| 75 | + let searchRecruitmentFlow = SearchRecruitmentFlow(container: container) |
| 76 | + |
| 77 | + Flows.use(searchRecruitmentFlow, when: .created) { (root) in |
| 78 | + let view = root as? SearchRecruitmentViewController |
| 79 | + self.rootViewController.navigationController?.pushViewController( |
| 80 | + view!, animated: true |
| 81 | + ) |
| 82 | + } |
| 83 | + |
| 84 | + return .one(flowContributor: .contribute( |
| 85 | + withNextPresentable: searchRecruitmentFlow, |
| 86 | + withNextStepper: OneStepper(withSingleStep: SearchRecruitmentStep.searchRecruitmentIsRequired) |
| 87 | + )) |
| 88 | + } |
| 89 | + |
| 90 | + func navigateToRecruitmentFilter() -> FlowContributors { |
| 91 | + let recruitmentFilterFlow = RecruitmentFilterFlow(container: container) |
| 92 | + |
| 93 | + Flows.use(recruitmentFilterFlow, when: .created) { (root) in |
| 94 | + self.rootViewController.navigationController?.pushViewController( |
| 95 | + root, animated: true |
| 96 | + ) |
| 97 | + } |
| 98 | + |
| 99 | + return .one(flowContributor: .contribute( |
| 100 | + withNextPresentable: recruitmentFilterFlow, |
| 101 | + withNextStepper: OneStepper(withSingleStep: RecruitmentFilterStep.recruitmentFilterIsRequired) |
| 102 | + )) |
| 103 | + } |
| 104 | +} |
0 commit comments