Skip to content

Commit 76c5b0d

Browse files
committed
Update site ID for POSTabCoordinator upon switching stores
1 parent ecfc2b3 commit 76c5b0d

File tree

4 files changed

+60
-9
lines changed

4 files changed

+60
-9
lines changed

WooCommerce/Classes/Bookings/BookingsTabView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ final class BookingsTabViewHostingController: UIHostingController<BookingsTabVie
1616
override var shouldShowOfflineBanner: Bool {
1717
return true
1818
}
19+
20+
func didSwitchStore(id: Int64) {
21+
// TODO: update view
22+
}
1923
}
2024

2125
private extension BookingsTabViewHostingController {

WooCommerce/Classes/POS/TabBar/POSTabCoordinator.swift

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class POSTabViewController: UIViewController {
2323
/// Coordinator for the Point of Sale tab.
2424
///
2525
final class POSTabCoordinator {
26-
private let siteID: Int64
26+
private(set) var siteID: Int64
2727
private let tabContainerController: TabContainerController
2828
private let viewControllerToPresent: UIViewController
2929
private let storesManager: StoresManager
@@ -107,12 +107,55 @@ final class POSTabCoordinator {
107107
}
108108

109109
func onTabSelected() {
110-
presentPOSView()
110+
presentPOSView(siteID: siteID)
111+
}
112+
113+
func didSwitchStore(id: Int64) {
114+
self.siteID = id
115+
116+
// Resets lazy properties so they get recreated with new siteID
117+
posItemFetchStrategyFactory = PointOfSaleItemFetchStrategyFactory(
118+
siteID: siteID,
119+
credentials: credentials,
120+
selectedSite: defaultSitePublisher,
121+
appPasswordSupportState: isAppPasswordSupported
122+
)
123+
124+
posPopularItemFetchStrategyFactory =
125+
PointOfSaleFixedItemFetchStrategyFactory(
126+
fixedStrategy: posItemFetchStrategyFactory.popularStrategy()
127+
)
128+
129+
posCouponFetchStrategyFactory = PointOfSaleCouponFetchStrategyFactory(
130+
siteID: siteID,
131+
currencySettings: currencySettings,
132+
credentials: credentials,
133+
selectedSite: defaultSitePublisher,
134+
appPasswordSupportState: isAppPasswordSupported,
135+
storage: storageManager
136+
)
137+
138+
posCouponProvider = PointOfSaleCouponService(
139+
siteID: siteID,
140+
currencySettings: currencySettings,
141+
credentials: credentials,
142+
selectedSite: defaultSitePublisher,
143+
appPasswordSupportState: isAppPasswordSupported,
144+
storage: storageManager
145+
)
146+
147+
barcodeScanService = PointOfSaleBarcodeScanService(
148+
siteID: siteID,
149+
credentials: credentials,
150+
selectedSite: defaultSitePublisher,
151+
appPasswordSupportState: isAppPasswordSupported,
152+
currencySettings: currencySettings
153+
)
111154
}
112155
}
113156

114157
private extension POSTabCoordinator {
115-
func presentPOSView() {
158+
func presentPOSView(siteID: Int64) {
116159
Task { @MainActor [weak self] in
117160
guard let self else { return }
118161
let serviceAdaptor = POSServiceLocatorAdaptor()

WooCommerce/Classes/ViewRelated/MainTabBarController.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -842,11 +842,15 @@ private extension MainTabBarController {
842842
}
843843
hubMenuTabCoordinator?.activate(siteID: siteID)
844844

845-
// Set dashboard to be the default tab - disable optional tabs by default.
846-
selectedIndex = WooTab.myStore.visibleIndex(isPOSTabVisible: false,
847-
isBookingsTabVisible: false)
848-
updateTabViewControllers(isPOSTabVisible: false,
849-
isBookingsTabVisible: false)
845+
// Sets dashboard to be the default tab.
846+
selectedIndex = WooTab.myStore.visibleIndex(isPOSTabVisible: isPOSTabVisible,
847+
isBookingsTabVisible: isBookingsTabVisible)
848+
849+
// Updates site ID for the POS coordinator to ensure correct data
850+
posTabCoordinator?.didSwitchStore(id: siteID)
851+
852+
// Updates site ID for the bookings tab to display correct bookings
853+
(bookingsContainerController.wrappedController as? BookingsTabViewHostingController)?.didSwitchStore(id: siteID)
850854
}
851855

852856
func createDashboardViewController(siteID: Int64) -> UIViewController {

WooCommerce/Classes/ViewRelated/NotificationsBadgeController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ final class NotificationsBadgeController {
6565
///
6666
private func hideDotOn(with input: NotificationsBadgeInput) {
6767
let tag = dotTag(for: input.tab)
68-
if let subviews = input.tabBar.orderedTabBarActionableViews[input.tabIndex].subviews.first?.subviews {
68+
if let subviews = input.tabBar.orderedTabBarActionableViews[safe: input.tabIndex]?.subviews.first?.subviews {
6969
for subview in subviews where subview.tag == tag {
7070
subview.fadeOut() { _ in
7171
subview.removeFromSuperview()

0 commit comments

Comments
 (0)