Skip to content

Commit

Permalink
Simplify itemList display
Browse files Browse the repository at this point in the history
  • Loading branch information
joshheald committed Oct 30, 2024
1 parent 3c48363 commit 74f084d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 37 deletions.
29 changes: 0 additions & 29 deletions WooCommerce/Classes/POS/PointOfSaleItemListState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,6 @@ enum PointOfSaleItemListState: Equatable {
case loaded([POSItem])
case error(PointOfSaleErrorState)

var isLoaded: Bool {
switch self {
case .loaded:
return true
default:
return false
}
}

var isLoading: Bool {
switch self {
case .loading:
return true
default:
return false
}
}

var hasError: PointOfSaleErrorState {
switch self {
case .error(let errorModel):
return errorModel
default:
return PointOfSaleErrorState(title: "Unknown error",
subtitle: "Unknown error",
buttonText: "Retry")
}
}

// Equatable conformance for testing:
static func == (lhs: PointOfSaleItemListState, rhs: PointOfSaleItemListState) -> Bool {
switch (lhs, rhs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,24 @@ struct PointOfSaleDashboardView: View {

var body: some View {
ZStack(alignment: .bottomLeading) {
if posModel.itemListState == .initialLoading {
switch posModel.itemListState {
case .initialLoading:
PointOfSaleLoadingView()
.transition(.opacity)
.ignoresSafeArea()
} else if viewModel.isError {
let errorContents = posModel.itemListState.hasError
case .error(let errorContents):
PointOfSaleItemListErrorView(error: errorContents, onRetry: {
Task {
await posModel.reloadItems()
}
})
} else if viewModel.isEmpty {
case .empty:
PointOfSaleItemListEmptyView()
} else {
case .loading, .loaded:
contentView
.accessibilitySortPriority(2)
}

POSFloatingControlView(posModel: posModel,
showExitPOSModal: $showExitPOSModal,
showSupport: $showSupport)
Expand Down
4 changes: 1 addition & 3 deletions WooCommerce/Classes/POS/ViewModels/ItemListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ final class ItemListViewModel: ItemListViewModelProtocol {
if UserDefaults.standard.bool(forKey: BannerState.isSimpleProductsOnlyBannerDismissedKey) == true {
return false
}
return !isHeaderBannerDismissed &&
(posModel.itemListState.isLoaded || posModel.itemListState.isLoading) &&
items.isNotEmpty
return !isHeaderBannerDismissed && items.isNotEmpty
}

init(posModel: PointOfSaleAggregateModel) {
Expand Down

0 comments on commit 74f084d

Please sign in to comment.