Skip to content

Commit 119776f

Browse files
committed
Return true if the store is already selected, and rename functions for more meaning
1 parent 88bbc06 commit 119776f

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

WooCommerce/Classes/ViewRelated/MainTabBarController.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ extension MainTabBarController {
337337
}
338338
let siteID = Int64(note.meta.identifier(forKey: .site) ?? Int.min)
339339

340-
switchToStore(with: siteID, onCompletion: { _ in
340+
showStore(with: siteID, onCompletion: { _ in
341341
presentNotificationDetails(for: note)
342342
})
343343
}
@@ -367,8 +367,16 @@ extension MainTabBarController {
367367
"already_read": note.read ])
368368
}
369369

370-
private static func switchToStore(with siteID: Int64, onCompletion: @escaping (Bool) -> Void) {
371-
SwitchStoreUseCase(stores: ServiceLocator.stores).switchToStoreIfSiteIsStored(with: siteID) { siteChanged in
370+
private static func showStore(with siteID: Int64, onCompletion: @escaping (Bool) -> Void) {
371+
let stores = ServiceLocator.stores
372+
373+
// Already showing that store, do nothing
374+
guard siteID != stores.sessionManager.defaultStoreID else {
375+
onCompletion(true)
376+
return
377+
}
378+
379+
SwitchStoreUseCase(stores: stores).switchToStoreIfSiteIsStored(with: siteID) { siteChanged in
372380
guard siteChanged else {
373381
return onCompletion(false)
374382
}
@@ -393,9 +401,9 @@ extension MainTabBarController {
393401
}
394402

395403
static func navigateToOrderDetails(with orderID: Int64, siteID: Int64) {
396-
switchToStore(with: siteID, onCompletion: { siteChanged in
404+
showStore(with: siteID, onCompletion: { storeIsShown in
397405
switchToOrdersTab {
398-
guard siteChanged else {
406+
guard storeIsShown else {
399407
return
400408
}
401409
// We give some time to the orders tab transition to finish, otherwise it might prevent the second navigation from happening

0 commit comments

Comments
 (0)