From 74f084d5b928619a624f34440363a5d4381fb7a8 Mon Sep 17 00:00:00 2001 From: Josh Heald Date: Wed, 30 Oct 2024 08:03:36 +0000 Subject: [PATCH] Simplify itemList display --- .../POS/PointOfSaleItemListState.swift | 29 ------------------- .../PointOfSaleDashboardView.swift | 11 +++---- .../POS/ViewModels/ItemListViewModel.swift | 4 +-- 3 files changed, 7 insertions(+), 37 deletions(-) diff --git a/WooCommerce/Classes/POS/PointOfSaleItemListState.swift b/WooCommerce/Classes/POS/PointOfSaleItemListState.swift index f0cf4c745a6..a643c6f87e1 100644 --- a/WooCommerce/Classes/POS/PointOfSaleItemListState.swift +++ b/WooCommerce/Classes/POS/PointOfSaleItemListState.swift @@ -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) { diff --git a/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift b/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift index 8f6eb26fca3..be3403d34fe 100644 --- a/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift +++ b/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift @@ -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) diff --git a/WooCommerce/Classes/POS/ViewModels/ItemListViewModel.swift b/WooCommerce/Classes/POS/ViewModels/ItemListViewModel.swift index 9fa03737d13..d8455c4db9c 100644 --- a/WooCommerce/Classes/POS/ViewModels/ItemListViewModel.swift +++ b/WooCommerce/Classes/POS/ViewModels/ItemListViewModel.swift @@ -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) {