-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NT-206] Reward received toggle business logic #866
Changes from 7 commits
1c11f9d
c915ee3
f436779
c9c4b38
bffa468
e0b2eb9
613819b
7ecdd46
de9c7dc
e74d94a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ import UIKit | |
final class ManagePledgeViewController: UIViewController { | ||
// MARK: - Properties | ||
|
||
private let viewModel: ManagePledgeViewModelType = ManagePledgeViewModel() | ||
|
||
private lazy var closeButton: UIBarButtonItem = { | ||
UIBarButtonItem( | ||
image: UIImage(named: "icon--cross"), | ||
|
@@ -44,15 +46,6 @@ final class ManagePledgeViewController: UIViewController { | |
|> \.translatesAutoresizingMaskIntoConstraints .~ false | ||
}() | ||
|
||
private let viewModel: ManagePledgeViewModelType = ManagePledgeViewModel() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've mostly used two step configuration
So I've gotten rid of this because it was effectively introducing pattern we've been trying to move away from and making the |
||
|
||
static func instantiate(with project: Project, reward: Reward) -> ManagePledgeViewController { | ||
let manageViewPledgeVC = ManagePledgeViewController.instantiate() | ||
manageViewPledgeVC.viewModel.inputs.configureWith(project, reward: reward) | ||
|
||
return manageViewPledgeVC | ||
} | ||
|
||
// MARK: - Lifecycle | ||
|
||
override func viewDidLoad() { | ||
|
@@ -95,6 +88,9 @@ final class ManagePledgeViewController: UIViewController { | |
override func bindViewModel() { | ||
super.bindViewModel() | ||
|
||
self.rewardReceivedViewController.view.rac.hidden = | ||
self.viewModel.outputs.rewardReceivedViewControllerViewIsHidden | ||
|
||
self.viewModel.outputs.title | ||
.observeForUI() | ||
.observeValues { [weak self] title in | ||
|
@@ -115,6 +111,12 @@ final class ManagePledgeViewController: UIViewController { | |
self?.pledgeSummaryView.configureWith(project) | ||
} | ||
|
||
self.viewModel.outputs.configureRewardReceivedWithProject | ||
.observeForControllerAction() | ||
.observeValues { [weak self] project in | ||
self?.rewardReceivedViewController.configureWith(project: project) | ||
} | ||
|
||
self.viewModel.outputs.configureRewardSummaryView | ||
.observeForUI() | ||
.observeValues { _ in } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,36 @@ | ||
import Library | ||
import KsApi | ||
import Prelude | ||
import UIKit | ||
|
||
final class ManageViewPledgeRewardReceivedViewController: ToggleViewController { | ||
// MARK: - Properties | ||
|
||
private let viewModel: ManageViewPledgeRewardReceivedViewModelType | ||
= ManageViewPledgeRewardReceivedViewModel() | ||
|
||
// MARK: - Lifecycle | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
self.toggle.addTarget(self, action: #selector(toggleValueDidChange(_:)), for: .valueChanged) | ||
|
||
self.viewModel.inputs.viewDidLoad() | ||
} | ||
|
||
// MARK: - Actions | ||
|
||
@objc private func toggleValueDidChange(_ toggle: UISwitch) { | ||
self.viewModel.inputs.rewardReceivedToggleTapped(isOn: toggle.isOn) | ||
} | ||
|
||
// MARK: - Configuration | ||
|
||
public func configureWith(project: Project) { | ||
self.viewModel.inputs.configureWith(project) | ||
} | ||
|
||
// MARK: - Styles | ||
|
||
override func bindStyles() { | ||
|
@@ -15,4 +43,16 @@ final class ManageViewPledgeRewardReceivedViewController: ToggleViewController { | |
_ = self.toggle | ||
|> checkoutSwitchControlStyle | ||
} | ||
|
||
// MARK: - View model | ||
|
||
override func bindViewModel() { | ||
super.bindViewModel() | ||
|
||
self.viewModel.outputs.rewardReceived | ||
.observeForUI() | ||
.observeValues { [weak self] isOn in | ||
self?.toggle.isOn = isOn | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't you add a RAC binding for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, got tripped by it being called |
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,14 +207,17 @@ public final class ProjectPamphletViewController: UIViewController { | |
} | ||
|
||
private func goToManageViewPledge(project: Project, reward: Reward, refTag _: RefTag?) { | ||
let managePledgeViewController = ManagePledgeViewController.instantiate(with: project, reward: reward) | ||
let vc = ManagePledgeViewController.instantiate() | ||
vc.configureWith(project: project, reward: reward) | ||
|
||
let nc = RewardPledgeNavigationController(rootViewController: vc) | ||
|
||
let nav = RewardPledgeNavigationController(rootViewController: managePledgeViewController) | ||
if AppEnvironment.current.device.userInterfaceIdiom == .pad { | ||
_ = nav | ||
_ = nc | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The diff would probably be small with less renaming here 😬 |
||
|> \.modalPresentationStyle .~ .formSheet | ||
} | ||
self.present(nav, animated: true) | ||
|
||
self.present(nc, animated: true) | ||
} | ||
|
||
private func goToDeprecatedManagePledge(project: Project, reward: Reward, refTag _: RefTag?) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,13 +21,14 @@ public protocol ManagePledgeViewModelInputs { | |
public protocol ManagePledgeViewModelOutputs { | ||
var configurePaymentMethodView: Signal<GraphUserCreditCard.CreditCard, Never> { get } | ||
var configurePledgeSummaryView: Signal<Project, Never> { get } | ||
var configureRewardReceivedWithProject: Signal<Project, Never> { get } | ||
var configureRewardSummaryView: Signal<Reward, Never> { get } | ||
var goToCancelPledge: Signal<(Project, Backing), Never> { get } | ||
var goToChangePaymentMethod: Signal<Void, Never> { get } | ||
var goToContactCreator: Signal<Void, Never> { get } | ||
var goToRewards: Signal<Project, Never> { get } | ||
var goToUpdatePledge: Signal<(Project, Reward), Never> { get } | ||
|
||
var rewardReceivedViewControllerViewIsHidden: Signal<Bool, Never> { get } | ||
var showActionSheetMenuWithOptions: Signal<[ManagePledgeAlertAction], Never> { get } | ||
var title: Signal<String, Never> { get } | ||
} | ||
|
@@ -43,6 +44,11 @@ public final class ManagePledgeViewModel: | |
let projectAndReward = self.projectAndRewardSignal | ||
.takeWhen(self.viewDidLoadSignal.ignoreValues()) | ||
|
||
let project = projectAndReward.map(first) | ||
let backing = project | ||
.map { $0.personalization.backing } | ||
.skipNil() | ||
|
||
self.title = projectAndReward | ||
.map(first) | ||
.map(navigationBarTitle(with:)) | ||
|
@@ -55,14 +61,11 @@ public final class ManagePledgeViewModel: | |
self.configurePledgeSummaryView = projectAndReward | ||
.map(first) | ||
|
||
self.configureRewardReceivedWithProject = project | ||
|
||
self.configureRewardSummaryView = projectAndReward | ||
.map(second) | ||
|
||
let project = projectAndReward.map(first) | ||
let backing = project | ||
.map { $0.personalization.backing } | ||
.skipNil() | ||
|
||
self.showActionSheetMenuWithOptions = project | ||
.takeWhen(self.menuButtonTappedSignal) | ||
.map { project -> [ManagePledgeAlertAction] in | ||
|
@@ -93,6 +96,9 @@ public final class ManagePledgeViewModel: | |
self.goToChangePaymentMethod = self.menuOptionSelectedSignal | ||
.filter { $0 == .changePaymentMethod } | ||
.ignoreValues() | ||
|
||
self.rewardReceivedViewControllerViewIsHidden = projectAndReward | ||
.map { project, reward in reward.isNoReward || project.personalization.backing?.status != .collected } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hopefully this is the same logic @eoji was trying to explain to me ... please let me know if I'm off here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :chefs_kiss: lgtm! |
||
} | ||
|
||
private let (projectAndRewardSignal, projectAndRewardObserver) = Signal<(Project, Reward), Never>.pipe() | ||
|
@@ -118,12 +124,14 @@ public final class ManagePledgeViewModel: | |
|
||
public let configurePaymentMethodView: Signal<GraphUserCreditCard.CreditCard, Never> | ||
public let configurePledgeSummaryView: Signal<Project, Never> | ||
public let configureRewardReceivedWithProject: Signal<Project, Never> | ||
public let configureRewardSummaryView: Signal<Reward, Never> | ||
public let goToCancelPledge: Signal<(Project, Backing), Never> | ||
public let goToChangePaymentMethod: Signal<Void, Never> | ||
public let goToContactCreator: Signal<Void, Never> | ||
public let goToRewards: Signal<Project, Never> | ||
public let goToUpdatePledge: Signal<(Project, Reward), Never> | ||
public let rewardReceivedViewControllerViewIsHidden: Signal<Bool, Never> | ||
public let showActionSheetMenuWithOptions: Signal<[ManagePledgeAlertAction], Never> | ||
public let title: Signal<String, Never> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved the
viewModel
to the top of Properties section. This is consistent with the rest of the codebase and makes it easier to glance at the same place where we would in other VC