Skip to content

Commit 11abe19

Browse files
committed
POC
1 parent 2cb584a commit 11abe19

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

WooCommerce/Classes/Bookings/BookingList/BookingListContainerViewModel.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,28 @@ final class BookingListContainerViewModel: ObservableObject {
8989
restorePersistedFilters()
9090
}
9191

92+
func pullToRefresh() async {
93+
async let today = todayListViewModel.onRefreshAction()
94+
async let upcoming = upcomingListViewModel.onRefreshAction(reason: "pull-to-refresh")
95+
async let all = allListViewModel.onRefreshAction(reason: "pull-to-refresh")
96+
_ = await (today, upcoming, all)
97+
}
98+
9299
func listViewModel(for tab: BookingListTab) -> BookingListViewModel {
100+
101+
102+
103+
todayListViewModel.parent = self
104+
upcomingListViewModel.parent = self
105+
allListViewModel.parent = self
106+
93107
switch tab {
94108
case .today:
95-
todayListViewModel
109+
return todayListViewModel
96110
case .upcoming:
97-
upcomingListViewModel
111+
return upcomingListViewModel
98112
case .all:
99-
allListViewModel
113+
return allListViewModel
100114
}
101115
}
102116

WooCommerce/Classes/Bookings/BookingList/BookingListView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ private extension BookingListView {
4343
switch viewModel.syncState {
4444
case .empty:
4545
emptyStateView(isSearching: false) {
46-
await viewModel.onRefreshAction()
46+
await viewModel.onRefreshAllAction()
4747
}
4848
case .syncingFirstPage:
4949
loadingView
5050
case .results:
5151
bookingList(with: viewModel.bookings,
5252
onNextPage: { viewModel.onLoadNextPageAction() },
53-
onRefresh: { await viewModel.onRefreshAction() })
53+
onRefresh: { await viewModel.onRefreshAllAction() })
5454
}
5555
}
5656
.overlay(alignment: .bottom) {

WooCommerce/Classes/Bookings/BookingList/BookingListViewModel.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ final class BookingListViewModel: ObservableObject {
1414

1515
@Published private(set) var hasFilters = false
1616

17+
weak var parent: BookingListContainerViewModel?
18+
1719
var emptyStateTitle: String {
1820
type.emptyStateTitle(hasFilters: hasFilters)
1921
}
@@ -58,6 +60,7 @@ final class BookingListViewModel: ObservableObject {
5860

5961
init(siteID: Int64,
6062
type: BookingListTab,
63+
parent: BookingListContainerViewModel? = nil,
6164
stores: StoresManager = ServiceLocator.stores,
6265
storage: StorageManagerType = ServiceLocator.storageManager,
6366
currentDate: Date = Date()) {
@@ -95,11 +98,15 @@ final class BookingListViewModel: ObservableObject {
9598
paginationTracker.ensureNextPageIsSynced()
9699
}
97100

101+
func onRefreshAllAction() async {
102+
await parent?.pullToRefresh()
103+
}
104+
98105
/// Called when the user pulls down the list to refresh.
99106
@MainActor
100-
func onRefreshAction() async {
107+
func onRefreshAction2(reason: String? = nil) async {
101108
await withCheckedContinuation { continuation in
102-
paginationTracker.resync(reason: Self.refreshCacheReason) {
109+
paginationTracker.resync(reason: reason ?? Self.refreshCacheReason) {
103110
continuation.resume(returning: ())
104111
}
105112
}

WooCommerce/Classes/Bookings/BookingList/BookingSearchViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ final class BookingSearchViewModel: ObservableObject {
5959

6060
/// Called when the user pulls down the list to refresh.
6161
@MainActor
62-
func onRefreshAction() async {
62+
func onRefreshAction(reason: String? = nil) async {
6363
await withCheckedContinuation { continuation in
6464
searchPaginationTracker.resync(reason: nil) {
6565
continuation.resume(returning: ())

0 commit comments

Comments
 (0)