Skip to content

Commit 8b7c352

Browse files
committed
Enable clearing cache upon pull to refresh
1 parent 40a77f2 commit 8b7c352

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

WooCommerce/Classes/Bookings/BookingList/BookingListViewModel.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ final class BookingListViewModel: ObservableObject {
1212
private let stores: StoresManager
1313
private let storage: StorageManagerType
1414

15+
private static let refreshCacheReason = "refresh-cache"
16+
1517
/// Keeps track of the current state of the syncing
1618
@Published private(set) var syncState: SyncState = .empty
1719

@@ -67,7 +69,7 @@ final class BookingListViewModel: ObservableObject {
6769
@MainActor
6870
func onRefreshAction() async {
6971
await withCheckedContinuation { continuation in
70-
paginationTracker.resync(reason: nil) {
72+
paginationTracker.resync(reason: Self.refreshCacheReason) {
7173
continuation.resume(returning: ())
7274
}
7375
}
@@ -107,11 +109,15 @@ private extension BookingListViewModel {
107109
extension BookingListViewModel: PaginationTrackerDelegate {
108110
func sync(pageNumber: Int, pageSize: Int, reason: String?, onCompletion: SyncCompletion?) {
109111
transitionToSyncingState()
110-
let action = BookingAction.synchronizeBookings(siteID: siteID,
111-
pageNumber: pageNumber,
112-
pageSize: pageSize,
113-
startDateBefore: type.startDateBefore?.ISO8601Format(),
114-
startDateAfter: type.startDateAfter?.ISO8601Format()) { [weak self] result in
112+
let shouldClearCache = reason == Self.refreshCacheReason
113+
let action = BookingAction.synchronizeBookings(
114+
siteID: siteID,
115+
pageNumber: pageNumber,
116+
pageSize: pageSize,
117+
startDateBefore: type.startDateBefore?.ISO8601Format(),
118+
startDateAfter: type.startDateAfter?.ISO8601Format(),
119+
shouldClearCache: shouldClearCache
120+
) { [weak self] result in
115121
switch result {
116122
case .success(let hasNextPage):
117123
onCompletion?(.success(hasNextPage))

0 commit comments

Comments
 (0)