11import Foundation
22import SwiftUI
3+ import enum Yosemite. POSCatalogSyncState
34
45struct PointOfSaleDashboardViewHelper {
56 static func determineViewState(
67 eligibilityState: POSEligibilityState ? ,
78 itemsContainerState: ItemsContainerState ,
8- horizontalSizeClass: UserInterfaceSizeClass ?
9+ horizontalSizeClass: UserInterfaceSizeClass ? ,
10+ catalogSyncState: POSCatalogSyncState ?
911 ) -> PointOfSaleDashboardView . ViewState {
12+
13+ /// Check first to show syncing state as soon as possible
14+ if let syncState = catalogSyncState {
15+ switch syncState {
16+ case . syncStarted( _, true ) :
17+ return . catalogSyncing
18+ case . syncNeverDone:
19+ return . catalogSyncing
20+ case . syncStarted( _, false ) :
21+ // Non-initial sync, continue to other checks
22+ break
23+ case . syncCompleted:
24+ // Continue to other checks
25+ break
26+ case . syncFailed:
27+ return . error( PointOfSaleErrorState . errorOnLoadingOrders ( ) )
28+ }
29+ }
30+
1031 guard case . regular = horizontalSizeClass else {
1132 return . unsupportedWidth
1233 }
@@ -17,6 +38,7 @@ struct PointOfSaleDashboardViewHelper {
1738
1839 switch eligibilityState {
1940 case . eligible:
41+ // Check items container state
2042 switch itemsContainerState {
2143 case . loading:
2244 return . loading
@@ -36,7 +58,7 @@ extension PointOfSaleDashboardView.ViewState {
3658 switch self {
3759 case . content, . error, . unsupportedWidth:
3860 return true
39- case . loading, . ineligible:
61+ case . loading, . ineligible, . catalogSyncing :
4062 return false
4163 }
4264 }
0 commit comments