POS Bookings: Address PR review feedback for date picker performance#16717
POS Bookings: Address PR review feedback for date picker performance#16717
Conversation
Replace with the existing fetchLocalBookings() protocol method which has the same implementation. Addresses PR review feedback.
Replace the complex ternary with a cacheClearStrategy(for:) method that clearly documents the logic. Addresses PR review feedback.
The method always re-fetches data for the date (intentionally naive to keep data fresh), so 'ifNeeded' was misleading. The only guard is against duplicate in-flight requests. Addresses PR review feedback.
The combined children accessibility element already provides sufficient context. The custom label was redundant and made announcements longer without adding new information. Addresses PR review feedback.
Instead of providing a default empty implementation in the protocol extension, add it explicitly to POSSearchBookingListFetchStrategy and other conformers. This makes it clearer that search doesn't use local storage, and forces new strategy implementations to consider this method. Addresses PR review feedback.
Rename showsLoadingWithItems to showsCachedDataWhileLoading to clarify that it controls whether cached data is displayed during a remote fetch. Rename and restructure setLocalDataOrLoadingState() to showCachedBookingsOrLoadingIndicator() with early returns and a doc comment explaining the three branches. Add comments to the strategy's sync-then-read pattern and the controller's two-phase loading flow. Addresses PR review feedback about code intent being hard to follow.
|
|
joshheald
left a comment
There was a problem hiding this comment.
Looks great, a few tiny things I spotted, but nothing very urgent. Thanks for the improvements.
Pagination – I noticed that if we scroll quickly to the bottom, the loading row doesn't show until we finish loading the first page. It does trigger the pagination without further scrolling, but it's difficult to spot.
WDYT about these two options:
- Optimistically add the pagination row even if we're not actually loading it yet, or
- Scroll to the loading row when we add it.
I prefer the first as we may mess up the user's scroll position with the second... but I recognise this is quite picky for our (probably) temporary solution, so no worries if the answer is "third, leave it as is."
| func clearSearchBookings() | ||
| } | ||
|
|
||
| @MainActor |
There was a problem hiding this comment.
There are good arguments that any @Observable should be @MainActor.
| guard paginationTracker.hasNextPage, | ||
| case .loaded(_, let hasMoreItems) = bookingsViewState, hasMoreItems else { return } | ||
|
|
||
| loadTask = Task { |
There was a problem hiding this comment.
Interesting, I didn't notice that we didn't put this in loadTask last time I reviewed. Was that just an error, previously, or is it to do with the pagination fixes?
| InfiniteScrollView( | ||
| triggerDeterminer: infiniteScrollTriggerDeterminer, | ||
| loadMore: { | ||
| guard case .loaded(_, let hasMoreItems) = bookingsViewState, hasMoreItems else { return } |
There was a problem hiding this comment.
Didn't notice this before but definitely seems better to take this logic out of the view 👍
| cacheClearStrategy: cacheClearStrategy | ||
| ) | ||
| let bookings = await fetchLocalBookingsFromStorage() | ||
| guard let filters else { return PagedItems(items: [], hasMorePages: hasMorePages, totalItems: nil) } |
There was a problem hiding this comment.
| guard let filters else { return PagedItems(items: [], hasMorePages: hasMorePages, totalItems: nil) } | |
| guard let filters else { | |
| return PagedItems(items: [], hasMorePages: hasMorePages, totalItems: nil) | |
| } |

Description
Addresses code review feedback from #16701.
Changes:
fetchLocalBookingsFromStoragefunctionprefetchDateIfNeededtoprefetchDate(always re-fetches, only guards against duplicate in-flight requests)POSBookingRowView(combined children default is sufficient)fetchLocalBookings()default from protocol extension to search strategy explicitlysyncBookings()call fromPOSBookingsModelinit toPOSBookingListControllerinitshowsLoadingWithItemstoshowsCachedDataWhileLoading, restructuresetLocalDataOrLoadingState()toshowCachedBookingsOrLoadingIndicator(), add comments clarifying the sync-then-read and two-phase loading patternsloadNextBookings()until first-page loading has finished andhasMoreItemsis true. We need to wait since we need to know if there's actually anything to paginate.Test Steps
Pagination
Quick paginate while the first page is still loading
Quick.Case.mov
Pagination only after the first page has loaded
Slow.Case.mov
Pagination + Date switches
Switching.Case.mov
RELEASE-NOTES.txtif necessary.