File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed
WooCommerce/Classes/ViewRelated/Coupons Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -41,15 +41,16 @@ final class CouponListViewController: UIViewController {
4141 . removeDuplicates ( )
4242 . sink { [ weak self] state in
4343 guard let self = self else { return }
44- self . removeNoResultsOverlay ( )
45- self . removePlaceholderCoupons ( )
44+ self . resetViews ( )
4645 switch state {
4746 case . empty:
4847 self . displayNoResultsOverlay ( )
4948 case . loading:
5049 self . displayPlaceholderCoupons ( )
5150 case . coupons:
5251 self . tableView. reloadData ( )
52+ case . refreshing:
53+ self . refreshControl. beginRefreshing ( )
5354 case . initialized:
5455 break
5556 }
@@ -63,9 +64,21 @@ final class CouponListViewController: UIViewController {
6364
6465// MARK: - Actions
6566private extension CouponListViewController {
67+ /// Triggers a refresh for the coupon list
68+ ///
6669 @objc func refreshCouponList( ) {
6770 viewModel. refreshCoupons ( )
6871 }
72+
73+ /// Removes overlays and loading indicators if present.
74+ ///
75+ func resetViews( ) {
76+ removeNoResultsOverlay ( )
77+ removePlaceholderCoupons ( )
78+ if refreshControl. isRefreshing {
79+ refreshControl. endRefreshing ( )
80+ }
81+ }
6982}
7083
7184
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ enum CouponListState {
1515 case loading // View should show ghost cells
1616 case empty // View should display the empty state
1717 case coupons // View should display the contents of `couponViewModels`
18+ case refreshing // View should display the refresh control
1819}
1920
2021final class CouponListViewModel {
@@ -139,7 +140,7 @@ extension CouponListViewModel: SyncingCoordinatorDelegate {
139140 pageSize: Int ,
140141 reason: String ? ,
141142 onCompletion: ( ( Bool ) -> Void ) ? ) {
142- transitionToSyncingState ( pageNumber: pageNumber)
143+ transitionToSyncingState ( pageNumber: pageNumber, hasData : couponViewModels . isNotEmpty )
143144 let action = CouponAction
144145 . synchronizeCoupons ( siteID: siteID,
145146 pageNumber: pageNumber,
@@ -168,9 +169,9 @@ extension CouponListViewModel: SyncingCoordinatorDelegate {
168169// MARK: - Pagination
169170//
170171private extension CouponListViewModel {
171- func transitionToSyncingState( pageNumber: Int ) {
172+ func transitionToSyncingState( pageNumber: Int , hasData : Bool ) {
172173 if pageNumber == 1 {
173- state = . loading
174+ state = hasData ? . refreshing : . loading
174175 }
175176 }
176177
You can’t perform that action at this time.
0 commit comments