@@ -4,18 +4,15 @@ import struct Yosemite.POSOrder
44import enum Yosemite. OrderPaymentMethod
55
66struct POSOrderListView : View {
7+ @Binding var isSearching : Bool
8+ @Binding var searchTerm : String
79 let onClose : ( ) -> Void
810
911 @Environment ( POSOrderListModel . self) private var orderListModel
10- @Environment ( \. keyboardObserver) private var keyboardObserver
1112 @Environment ( \. posAnalytics) private var analytics
1213 @Environment ( \. siteTimezone) private var siteTimezone
1314 @StateObject private var infiniteScrollTriggerDeterminer = ThresholdInfiniteScrollTriggerDeterminer ( )
1415
15- @State private var isSearching : Bool = false
16- @State private var searchTerm : String = " "
17- @Namespace private var searchTransition
18-
1916 private var ordersViewState : POSOrderListState {
2017 orderListModel. ordersController. ordersViewState
2118 }
@@ -46,8 +43,11 @@ struct POSOrderListView: View {
4643 setSearch ( true )
4744 }
4845 . accessibilityLabel ( Localization . searchButtonAccessibilityLabel)
49- . matchedGeometryEffect ( id: Constants . searchControlID, in: searchTransition)
50- . transition ( . opacity. combined ( with: . scale) )
46+ . transition ( . asymmetric(
47+ insertion: . scale. combined ( with: . opacity)
48+ . animation ( . easeInOut( duration: Constants . animationDuration) . delay ( Constants . animationDuration) ) ,
49+ removal: . opacity. animation ( . easeInOut( duration: Constants . animationDuration * 0.5 ) )
50+ ) )
5151 }
5252
5353 if isSearching {
@@ -59,8 +59,12 @@ struct POSOrderListView: View {
5959 }
6060 )
6161 . posSearchTextFieldUnfocusedBorderColor ( . posOutlineVariant)
62- . matchedGeometryEffect ( id: Constants . searchControlID, in: searchTransition)
63- . transition ( . opacity. combined ( with: . move( edge: . leading) ) )
62+ . transition ( . asymmetric(
63+ insertion: . opacity. combined ( with: . move( edge: . trailing) )
64+ . animation ( . easeInOut( duration: Constants . animationDuration) . delay ( Constants . animationDuration * 0.5 ) ) ,
65+ removal: . opacity. combined ( with: . move( edge: . trailing) )
66+ . animation ( . easeInOut( duration: Constants . animationDuration) )
67+ ) )
6468 . onChange ( of: searchTerm) { _, newValue in
6569 if newValue. isEmpty {
6670 orderListModel. ordersController. clearSearchOrders ( )
@@ -71,23 +75,21 @@ struct POSOrderListView: View {
7175 )
7276 . animation ( . easeInOut( duration: Constants . animationDuration) , value: isSearching)
7377
74- switch ordersViewState {
75- case . empty:
78+ switch ( ordersViewState, isSearching ) {
79+ case ( . empty, true ) :
7680 POSListEmptyView (
77- viewModel: POSOrderListEmptyViewModel ( isSearching: isSearching )
81+ viewModel: POSOrderListEmptyViewModel ( isSearching: true )
7882 ) {
7983 Task { @MainActor in
8084 await orderListModel. ordersController. loadOrders ( )
8185 }
8286 }
83- . padding ( . bottom, keyboardObserver. keyboardHeight)
84- case . error( let errorState) :
87+ case ( . error( let errorState) , true ) :
8588 POSListErrorView ( error: errorState) {
8689 Task { @MainActor in
8790 await orderListModel. ordersController. loadOrders ( )
8891 }
8992 }
90- . padding ( . bottom, keyboardObserver. keyboardHeight)
9193 default :
9294 listView
9395 }
@@ -99,9 +101,6 @@ struct POSOrderListView: View {
99101 analytics. track ( event: WooAnalyticsEvent . PointOfSale. ordersListPullToRefresh ( ) )
100102 await orderListModel. ordersController. refreshOrders ( )
101103 }
102- . task {
103- await orderListModel. ordersController. loadOrders ( )
104- }
105104 }
106105
107106 @ViewBuilder
@@ -128,7 +127,7 @@ struct POSOrderListView: View {
128127 await orderListModel. ordersController. loadNextOrders ( )
129128 } ,
130129 content: {
131- LazyVStack ( spacing: POSSpacing . small ) {
130+ LazyVStack ( spacing: POSSpacing . medium ) {
132131 headerRows
133132 . id ( Constants . scrollTopID)
134133
@@ -384,7 +383,6 @@ private enum Constants {
384383 static let orderCardMinHeight : CGFloat = 112
385384 static let maximumOrderCardHeight : CGFloat = Constants . orderCardMinHeight * 2
386385 static let animationDuration : CGFloat = 0.2
387- static let searchControlID = " searchControl "
388386 static let scrollTopID = " orderListViewTopID "
389387}
390388
@@ -450,7 +448,7 @@ private enum Localization {
450448#if DEBUG
451449#Preview( " List " ) {
452450 NavigationSplitView ( columnVisibility: . constant( . all) ) {
453- POSOrderListView ( onClose: { } )
451+ POSOrderListView ( isSearching : . constant ( false ) , searchTerm : . constant ( " " ) , onClose: { } )
454452 . navigationSplitViewColumnWidth ( 450 )
455453 . environment ( POSPreviewHelpers . makePreviewOrdersModel ( state: POSPreviewHelpers . loadedState ( ) ) )
456454 } detail: {
@@ -459,19 +457,19 @@ private enum Localization {
459457 . navigationSplitViewStyle ( . balanced)
460458}
461459
462- #Preview( " Empty State " ) {
460+ #Preview( " Empty State in Search " ) {
463461 NavigationSplitView ( columnVisibility: . constant( . all) ) {
464- POSOrderListView ( onClose: { } )
462+ POSOrderListView ( isSearching : . constant ( true ) , searchTerm : . constant ( " " ) , onClose: { } )
465463 . navigationSplitViewColumnWidth ( 450 )
466464 . environment ( POSPreviewHelpers . makePreviewOrdersModel ( state: . empty) )
467465 } detail: {
468466 Text ( " Detail View " )
469467 }
470468}
471469
472- #Preview( " Error State " ) {
470+ #Preview( " Error State in Search " ) {
473471 NavigationSplitView ( columnVisibility: . constant( . all) ) {
474- POSOrderListView ( onClose: { } )
472+ POSOrderListView ( isSearching : . constant ( true ) , searchTerm : . constant ( " " ) , onClose: { } )
475473 . navigationSplitViewColumnWidth ( 450 )
476474 . environment ( POSPreviewHelpers . makePreviewOrdersModel ( state: . error( . errorOnLoadingOrders( ) ) ) )
477475 } detail: {
@@ -481,7 +479,7 @@ private enum Localization {
481479
482480#Preview( " Loading State " ) {
483481 NavigationSplitView ( columnVisibility: . constant( . all) ) {
484- POSOrderListView ( onClose: { } )
482+ POSOrderListView ( isSearching : . constant ( false ) , searchTerm : . constant ( " " ) , onClose: { } )
485483 . navigationSplitViewColumnWidth ( 450 )
486484 . environment ( POSPreviewHelpers . makePreviewOrdersModel ( state: . loading( [ ] ) ) )
487485 } detail: {
@@ -491,7 +489,7 @@ private enum Localization {
491489
492490#Preview( " Inline Error - Refresh " ) {
493491 NavigationSplitView ( columnVisibility: . constant( . all) ) {
494- POSOrderListView ( onClose: { } )
492+ POSOrderListView ( isSearching : . constant ( false ) , searchTerm : . constant ( " " ) , onClose: { } )
495493 . navigationSplitViewColumnWidth ( 450 )
496494 . environment ( POSPreviewHelpers . makePreviewOrdersModel (
497495 state: . inlineError( POSPreviewHelpers . makePreviewOrders ( ) ,
@@ -505,7 +503,7 @@ private enum Localization {
505503
506504#Preview( " Inline Error - Pagination " ) {
507505 NavigationSplitView ( columnVisibility: . constant( . all) ) {
508- POSOrderListView ( onClose: { } )
506+ POSOrderListView ( isSearching : . constant ( false ) , searchTerm : . constant ( " " ) , onClose: { } )
509507 . navigationSplitViewColumnWidth ( 450 )
510508 . environment ( POSPreviewHelpers . makePreviewOrdersModel (
511509 state: . inlineError( POSPreviewHelpers . makePreviewOrders ( ) ,
@@ -519,7 +517,7 @@ private enum Localization {
519517
520518#Preview( " Search Empty State " ) {
521519 NavigationSplitView ( columnVisibility: . constant( . all) ) {
522- POSOrderListView ( onClose: { } )
520+ POSOrderListView ( isSearching : . constant ( true ) , searchTerm : . constant ( " " ) , onClose: { } )
523521 . navigationSplitViewColumnWidth ( 450 )
524522 . environment ( POSPreviewHelpers . makePreviewOrdersModel ( state: . empty) )
525523 } detail: {
0 commit comments