Skip to content

Commit

Permalink
Refactor FXIOS-7429 [v119] Integrate onboarding in bottom sheet (#16472)
Browse files Browse the repository at this point in the history
* Add onboarding card to view controller

* Display onboarding if user is not opted in yet

* Optimize code
  • Loading branch information
thatswinnie authored Sep 20, 2023
1 parent 1f33c05 commit 742dad4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion Client/Frontend/Fakespot/FakespotViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class FakespotViewController: UIViewController, Themeable, UIAdaptivePresentatio
private func updateContent() {
contentStackView.removeAllArrangedViews()

viewModel.state.viewElements.forEach { element in
viewModel.viewElements.forEach { element in
guard let view = createContentView(viewElement: element) else { return }
contentStackView.addArrangedSubview(view)

Expand All @@ -177,6 +177,12 @@ class FakespotViewController: UIViewController, Themeable, UIAdaptivePresentatio
let view: FakespotLoadingView = .build()
return view

case .onboarding:
let viewModel = FakespotOptInCardViewModel()
let view: FakespotOptInCardView = .build()
view.configure(viewModel)
return view

case .reliabilityCard:
guard let cardViewModel = viewModel.reliabilityCardViewModel else { return nil }
let view: FakespotReliabilityCardView = .build()
Expand Down
8 changes: 4 additions & 4 deletions Client/Frontend/Fakespot/FakespotViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FakespotViewModel {
case loaded(ProductAnalysisData?)
case error(Error)

var viewElements: [ViewElement] {
fileprivate var viewElements: [ViewElement] {
var elements: [ViewElement] = []

switch self {
Expand All @@ -38,7 +38,7 @@ class FakespotViewModel {
return elements
}

var productData: ProductAnalysisData? {
fileprivate var productData: ProductAnalysisData? {
switch self {
case .loading, .error: return nil
case .loaded(let data): return data
Expand All @@ -48,7 +48,7 @@ class FakespotViewModel {

enum ViewElement {
case loadingView
// case onboarding // card not created yet (FXIOS-7270)
case onboarding
case reliabilityCard
case adjustRatingCard
case highlightsCard
Expand All @@ -68,7 +68,7 @@ class FakespotViewModel {
var onStateChange: (() -> Void)?

var viewElements: [ViewElement] {
// guard isOptedIn else { return [.onboarding] } // card not created yet (FXIOS-7270)
guard isOptedIn else { return [.onboarding] }

return state.viewElements
}
Expand Down

0 comments on commit 742dad4

Please sign in to comment.