Skip to content

Commit cfe11f7

Browse files
Merge pull request #548 from woocommerce/issue/542-notification-filter
Notification List: Updates FSM states and placeholders
2 parents 6342959 + 446de7d commit cfe11f7

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

WooCommerce/Classes/ViewRelated/Notifications/NotificationsViewController.swift

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ private extension NotificationsViewController {
291291

292292
// Filter right away the cached orders
293293
refreshResultsPredicate()
294+
transitionToResultsUpdatedState()
294295
}
295296
}
296297

@@ -604,9 +605,24 @@ private extension NotificationsViewController {
604605
resultsController.startForwardingEvents(to: self.tableView)
605606
}
606607

608+
609+
/// Displays the Empty State (with filters applied!) Overlay.
610+
///
611+
func displayEmptyFilteredOverlay() {
612+
let overlayView: OverlayMessageView = OverlayMessageView.instantiateFromNib()
613+
overlayView.messageImage = .waitingForCustomersImage
614+
overlayView.messageText = NSLocalizedString("No results for the selected criteria", comment: "Notifications List (Empty State + Filters)")
615+
overlayView.actionText = NSLocalizedString("Remove Filters", comment: "Action: removes the current filters from the notifications list")
616+
overlayView.onAction = { [weak self] in
617+
self?.currentTypeFilter = .all
618+
}
619+
620+
overlayView.attach(to: view)
621+
}
622+
607623
/// Displays the Empty State Overlay.
608624
///
609-
func displayEmptyNotesOverlay() {
625+
func displayEmptyUnfilteredOverlay() {
610626
let overlayView: OverlayMessageView = OverlayMessageView.instantiateFromNib()
611627
overlayView.messageImage = .waitingForCustomersImage
612628
overlayView.messageText = NSLocalizedString("No Notifications Yet!", comment: "Empty Notifications List Message")
@@ -684,9 +700,12 @@ private extension NotificationsViewController {
684700
///
685701
func didEnter(state: State) {
686702
switch state {
687-
case .empty:
688-
displayEmptyNotesOverlay()
703+
case .emptyUnfiltered:
704+
displayEmptyUnfilteredOverlay()
689705
updateNavBarButtonsState(enabled: false)
706+
case .emptyFiltered:
707+
displayEmptyFilteredOverlay()
708+
updateNavBarButtonsState(enabled: true)
690709
case .results:
691710
updateNavBarButtonsState(enabled: true)
692711
break
@@ -700,7 +719,9 @@ private extension NotificationsViewController {
700719
///
701720
func didLeave(state: State) {
702721
switch state {
703-
case .empty:
722+
case .emptyFiltered:
723+
removeAllOverlays()
724+
case .emptyUnfiltered:
704725
removeAllOverlays()
705726
case .results:
706727
break
@@ -715,10 +736,21 @@ private extension NotificationsViewController {
715736
state = isEmpty ? .syncing : .results
716737
}
717738

718-
/// Should be called after Sync'ing wraps up: Transitions to .empty / .results
739+
/// Should be called whenever the results are updated: after Sync'ing (or after applying a filter).
740+
/// Transitions to `.results` / `.emptyFiltered` / `.emptyUnfiltered` accordingly.
719741
///
720742
func transitionToResultsUpdatedState() {
721-
state = isEmpty ? .empty : .results
743+
if isEmpty == false {
744+
state = .results
745+
return
746+
}
747+
748+
if currentTypeFilter != .all {
749+
state = .emptyFiltered
750+
return
751+
}
752+
753+
state = .emptyUnfiltered
722754
}
723755
}
724756

@@ -771,7 +803,8 @@ private extension NotificationsViewController {
771803
}
772804

773805
enum State {
774-
case empty
806+
case emptyUnfiltered
807+
case emptyFiltered
775808
case results
776809
case syncing
777810
}

0 commit comments

Comments
 (0)