Skip to content

Commit eb36ab4

Browse files
authored
Merge pull request #6963 from woocommerce/fix/1810-review-notification
Attempt to fix review details not shown after tapping a push notification
2 parents 661f531 + aad72a9 commit eb36ab4

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

WooCommerce/Classes/ViewRelated/Hub Menu/HubMenu.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ struct HubMenu: View {
2121
///
2222
private let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
2323

24-
init(siteID: Int64, navigationController: UINavigationController? = nil) {
25-
viewModel = HubMenuViewModel(siteID: siteID, navigationController: navigationController)
24+
init(viewModel: HubMenuViewModel) {
25+
self.viewModel = viewModel
2626
}
2727

2828
var body: some View {
@@ -111,10 +111,6 @@ struct HubMenu: View {
111111
}
112112
}
113113

114-
func pushReviewDetailsView(using parcel: ProductReviewFromNoteParcel) {
115-
viewModel.showReviewDetails(using: parcel)
116-
}
117-
118114
/// Reset state to make the menu items tappable
119115
private func enableMenuItemTaps() {
120116
shouldDisableItemTaps = false
@@ -213,17 +209,17 @@ struct HubMenu: View {
213209

214210
struct HubMenu_Previews: PreviewProvider {
215211
static var previews: some View {
216-
HubMenu(siteID: 123)
212+
HubMenu(viewModel: .init(siteID: 123))
217213
.environment(\.colorScheme, .light)
218214

219-
HubMenu(siteID: 123)
215+
HubMenu(viewModel: .init(siteID: 123))
220216
.environment(\.colorScheme, .dark)
221217

222-
HubMenu(siteID: 123)
218+
HubMenu(viewModel: .init(siteID: 123))
223219
.previewLayout(.fixed(width: 312, height: 528))
224220
.environment(\.sizeCategory, .accessibilityExtraExtraExtraLarge)
225221

226-
HubMenu(siteID: 123)
222+
HubMenu(viewModel: .init(siteID: 123))
227223
.previewLayout(.fixed(width: 1024, height: 768))
228224
}
229225
}

WooCommerce/Classes/ViewRelated/Hub Menu/HubMenuCoordinator.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ final class HubMenuCoordinator: Coordinator {
2020

2121
private var notificationsSubscription: AnyCancellable?
2222

23-
private let willPresentReviewDetailsFromPushNotification: () -> Void
23+
private let willPresentReviewDetailsFromPushNotification: () async -> Void
2424

2525
init(navigationController: UINavigationController,
2626
pushNotificationsManager: PushNotesManager = ServiceLocator.pushNotesManager,
2727
storesManager: StoresManager = ServiceLocator.stores,
2828
noticePresenter: NoticePresenter = ServiceLocator.noticePresenter,
2929
switchStoreUseCase: SwitchStoreUseCaseProtocol,
30-
willPresentReviewDetailsFromPushNotification: @escaping () -> Void) {
30+
willPresentReviewDetailsFromPushNotification: @escaping () async -> Void) {
3131

3232
self.pushNotificationsManager = pushNotificationsManager
3333
self.storesManager = storesManager
@@ -37,7 +37,7 @@ final class HubMenuCoordinator: Coordinator {
3737
self.navigationController = navigationController
3838
}
3939

40-
convenience init(navigationController: UINavigationController, willPresentReviewDetailsFromPushNotification: @escaping () -> Void) {
40+
convenience init(navigationController: UINavigationController, willPresentReviewDetailsFromPushNotification: @escaping () async -> Void) {
4141
let storesManager = ServiceLocator.stores
4242
self.init(navigationController: navigationController,
4343
storesManager: storesManager,
@@ -94,13 +94,15 @@ final class HubMenuCoordinator: Coordinator {
9494
return
9595
}
9696

97-
self.willPresentReviewDetailsFromPushNotification()
98-
self.pushReviewDetailsViewController(using: parcel)
97+
Task { @MainActor in
98+
await self.willPresentReviewDetailsFromPushNotification()
99+
self.pushReviewDetailsViewController(using: parcel)
99100

100-
if siteChanged {
101-
let presenter = SwitchStoreNoticePresenter(siteID: Int64(siteID),
102-
noticePresenter: self.noticePresenter)
103-
presenter.presentStoreSwitchedNoticeWhenSiteIsAvailable(configuration: .switchingStores)
101+
if siteChanged {
102+
let presenter = SwitchStoreNoticePresenter(siteID: Int64(siteID),
103+
noticePresenter: self.noticePresenter)
104+
presenter.presentStoreSwitchedNoticeWhenSiteIsAvailable(configuration: .switchingStores)
105+
}
104106
}
105107
}
106108
}

WooCommerce/Classes/ViewRelated/Hub Menu/HubMenuViewController.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import Yosemite
44

55
/// Displays a grid view of all available menu in the "Menu" tab (eg. View Store, Reviews, Coupons, etc...)
66
final class HubMenuViewController: UIHostingController<HubMenu> {
7+
private let viewModel: HubMenuViewModel
78

89
init(siteID: Int64, navigationController: UINavigationController?) {
9-
super.init(rootView: HubMenu(siteID: siteID, navigationController: navigationController))
10+
self.viewModel = HubMenuViewModel(siteID: siteID, navigationController: navigationController)
11+
super.init(rootView: HubMenu(viewModel: viewModel))
1012
configureTabBarItem()
1113
}
1214

@@ -17,7 +19,7 @@ final class HubMenuViewController: UIHostingController<HubMenu> {
1719
/// Present the specific Review Details View from a push notification
1820
///
1921
func pushReviewDetailsViewController(using parcel: ProductReviewFromNoteParcel) {
20-
rootView.pushReviewDetailsView(using: parcel)
22+
viewModel.showReviewDetails(using: parcel)
2123
}
2224
}
2325

WooCommerce/Classes/ViewRelated/MainTabBarController.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,11 @@ private extension MainTabBarController {
481481
func createHubMenuTabCoordinator() -> HubMenuCoordinator {
482482
HubMenuCoordinator(navigationController: hubMenuNavigationController,
483483
willPresentReviewDetailsFromPushNotification: { [weak self] in
484-
self?.navigateTo(.hubMenu)
484+
await withCheckedContinuation { [weak self] continuation in
485+
self?.navigateTo(.hubMenu) {
486+
continuation.resume(returning: ())
487+
}
488+
}
485489
})
486490
}
487491
}

0 commit comments

Comments
 (0)