Skip to content

Commit c1b56e0

Browse files
authored
Inbox: Fix unreliable states for the inbox list from Hub Menu (#13645)
2 parents 765bca3 + 765ebad commit c1b56e0

File tree

5 files changed

+35
-34
lines changed

5 files changed

+35
-34
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private extension HubMenu {
159159
title: HubMenuViewModel.Localization.viewStore,
160160
shouldAuthenticate: false)
161161
case HubMenuViewModel.Inbox.id:
162-
Inbox(viewModel: .init(siteID: viewModel.siteID))
162+
Inbox(viewModel: viewModel.inboxViewModel)
163163
case HubMenuViewModel.Reviews.id:
164164
ReviewsView(siteID: viewModel.siteID)
165165
case HubMenuViewModel.Coupons.id:

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ final class HubMenuViewModel: ObservableObject {
8888
credentials: credentials)
8989
}()
9090

91+
private(set) lazy var inboxViewModel = InboxViewModel(siteID: siteID)
92+
9193
private(set) var productReviewFromNoteParcel: ProductReviewFromNoteParcel?
9294

9395
@Published private(set) var shouldShowNewFeatureBadgeOnPayments: Bool = false

WooCommerce/Classes/ViewRelated/Inbox/Inbox.swift

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,6 @@ struct Inbox: View {
1818

1919
var body: some View {
2020
VStack(alignment: .leading, spacing: 0) {
21-
// Anchor the action sheet at the top to be able to show the popover on iPad in the most appropriate position
22-
// When the app supports iOS 15+, we can remove this workaround by moving the `actionSheet` and `alert` calls to the `ToolbarItem`'s button.
23-
Divider()
24-
.hidden()
25-
.actionSheet(isPresented: $showingActionSheet) {
26-
ActionSheet(
27-
title: Text(Localization.title),
28-
buttons: [
29-
.default(Text(Localization.dismissAllNotes), action: {
30-
showingDismissAlert = true
31-
}),
32-
.cancel()
33-
]
34-
)
35-
}
36-
.alert(isPresented: $showingDismissAlert) {
37-
return Alert(title: Text(Localization.dismissAllNotesAlertTitle),
38-
message: Text(Localization.dismissAllNotesAlertMessage),
39-
primaryButton: .default(Text(Localization.dismissAllNotes), action: viewModel.dismissAllInboxNotes),
40-
secondaryButton: .cancel())
41-
}
42-
4321
Group {
4422
switch viewModel.syncState {
4523
case .results:
@@ -83,16 +61,33 @@ struct Inbox: View {
8361
}
8462
.toolbar {
8563
ToolbarItem(placement: .navigationBarTrailing) {
86-
Button(action: {
87-
showingActionSheet = true
88-
}, label: {
89-
Image(uiImage: .moreImage)
90-
.renderingMode(.template)
91-
})
92-
.renderedIf(viewModel.syncState == .results)
64+
if viewModel.syncState == .results {
65+
Button(action: {
66+
showingActionSheet = true
67+
}, label: {
68+
Image(uiImage: .moreImage)
69+
.renderingMode(.template)
70+
})
71+
.confirmationDialog(Localization.title, isPresented: $showingActionSheet) {
72+
Button(Localization.dismissAllNotes) {
73+
showingDismissAlert = true
74+
}
75+
}
76+
}
9377
}
9478
}
95-
.wooNavigationBarStyle()
79+
.alert(Localization.dismissAllNotesAlertTitle, isPresented: $showingDismissAlert, actions: {
80+
Button(Localization.dismissAllNotes) {
81+
showingDismissAlert = false
82+
viewModel.dismissAllInboxNotes()
83+
}
84+
85+
Button(Localization.cancel) {
86+
showingDismissAlert = false
87+
}
88+
}, message: {
89+
Text(Localization.dismissAllNotesAlertMessage)
90+
})
9691
}
9792
}
9893
}
@@ -116,6 +111,11 @@ private extension Inbox {
116111
comment: "Title of the alert for dismissing all the inbox notes.")
117112
static let dismissAllNotesAlertMessage = NSLocalizedString("Are you sure? Inbox messages will be dismissed forever.",
118113
comment: "Message displayed in the alert for dismissing all the inbox notes.")
114+
static let cancel = NSLocalizedString(
115+
"inbox.alert.cancel",
116+
value: "Cancel",
117+
comment: "Button to dismiss the confirmation alert on the Inbox screen."
118+
)
119119
}
120120
}
121121

WooCommerce/Classes/ViewRelated/Inbox/InboxViewModel.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ private extension InboxViewModel {
169169
}
170170

171171
func configureFirstPageLoad() {
172-
// Listens only to the first emitted event.
173-
onLoadTrigger.first()
172+
onLoadTrigger
174173
.sink { [weak self] in
175174
guard let self = self else { return }
176175
self.syncFirstPage()

WooCommerce/WooCommerceTests/ViewRelated/Inbox/InboxViewModelTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ final class InboxViewModelTests: XCTestCase {
6565
// Then
6666
XCTAssertEqual(stateAfterTheFirstOnLoadTrigger, .syncingFirstPage)
6767
XCTAssertEqual(stateAfterTheSecondOnLoadTrigger, .syncingFirstPage)
68-
XCTAssertEqual(invocationCountOfLoadInboxNotes, 1)
68+
XCTAssertEqual(invocationCountOfLoadInboxNotes, 2)
6969
}
7070

7171
func test_state_is_results_after_onLoadTrigger_with_nonempty_results() {

0 commit comments

Comments
 (0)