Skip to content

Commit 5b4457a

Browse files
committed
Trigger add product flow for products onboarding without switching tabs
Remove unused code for presenting add product flow
1 parent 64979b3 commit 5b4457a

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewController.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ final class DashboardViewController: UIViewController {
123123
observeStatsVersionForDashboardUIUpdates()
124124
observeAnnouncements()
125125
observeShowWebViewSheet()
126+
observeAddProductTrigger()
126127
viewModel.syncAnnouncements(for: siteID)
127128
Task { @MainActor in
128129
await reloadDashboardUIStatsVersion(forced: true)
@@ -303,6 +304,23 @@ private extension DashboardViewController {
303304
present(hostingController, animated: true, completion: nil)
304305
}
305306

307+
/// Subscribes to the trigger to start the Add Product flow for products onboarding
308+
///
309+
private func observeAddProductTrigger() {
310+
viewModel.addProductTrigger.sink { [weak self] _ in
311+
self?.startAddProductFlow()
312+
}
313+
.store(in: &subscriptions)
314+
}
315+
316+
/// Starts the Add Product flow (without switching tabs)
317+
///
318+
private func startAddProductFlow() {
319+
guard let announcementView, let navigationController else { return }
320+
let coordinator = AddProductCoordinator(siteID: siteID, sourceView: announcementView, sourceNavigationController: navigationController)
321+
coordinator.start()
322+
}
323+
306324
// This is used so we have a specific type for the view while applying modifiers.
307325
struct AnnouncementCardWrapper: View {
308326
let cardView: FeatureAnnouncementCardView

WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewModel.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Yosemite
2+
import Combine
23
import enum Networking.DotcomError
34
import enum Storage.StatsVersion
45
import protocol Experiments.FeatureFlagService
@@ -13,6 +14,10 @@ final class DashboardViewModel {
1314

1415
@Published private(set) var showWebViewSheet: WebViewSheetViewModel? = nil
1516

17+
/// Trigger to start the Add Product flow
18+
///
19+
let addProductTrigger = PassthroughSubject<Void, Never>()
20+
1621
private let stores: StoresManager
1722
private let featureFlagService: FeatureFlagService
1823
private let analytics: Analytics
@@ -154,8 +159,7 @@ final class DashboardViewModel {
154159
guard let self else { return }
155160
if case let .success(isVisible) = result, isVisible {
156161
let viewModel = ProductsOnboardingAnnouncementCardViewModel(onCTATapped: { [weak self] in
157-
self?.announcementViewModel = nil // Dismiss announcement
158-
MainTabBarController.presentAddProductFlow()
162+
self?.addProductTrigger.send()
159163
})
160164
self.announcementViewModel = viewModel
161165
}

WooCommerce/Classes/ViewRelated/MainTabBarController.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -414,19 +414,6 @@ extension MainTabBarController {
414414
}
415415
}
416416

417-
static func presentAddProductFlow() {
418-
navigateTo(.products)
419-
420-
guard let productsViewController: ProductsViewController = childViewController() else {
421-
return
422-
}
423-
424-
// We give some time for the products tab transition to finish, so the add product button is present to start the flow
425-
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
426-
productsViewController.addProduct()
427-
}
428-
}
429-
430417
static func presentPayments() {
431418
switchToHubMenuTab()
432419

WooCommerce/Classes/ViewRelated/Products/ProductsViewController.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,6 @@ final class ProductsViewController: UIViewController, GhostableViewController {
220220
}
221221
}
222222

223-
// MARK: - Public API
224-
//
225-
extension ProductsViewController {
226-
/// Adds a new product using the "Add Product" navigation bar button as the source
227-
///
228-
func addProduct() {
229-
addProduct(addProductButton)
230-
}
231-
}
232-
233223
// MARK: - Navigation Bar Actions
234224
//
235225
private extension ProductsViewController {

0 commit comments

Comments
 (0)