Skip to content

Commit 3616738

Browse files
committed
Update ViewController to show and hide fetching and creting blocking indicators
1 parent e0b34cf commit 3616738

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

WooCommerce/Classes/ViewRelated/Products/Variations/ProductVariationsViewController.swift

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,40 @@ private extension ProductVariationsViewController {
639639
controller.addCancelActionWithTitle(Localization.cancel) { _ in
640640
onCompletion(false)
641641
}
642-
present(controller, animated: true)
642+
643+
// There should be an `inProgressViewController` being presented. Fallback to `self` in case there isn't one.
644+
let baseViewController = presentedViewController ?? self
645+
baseViewController.present(controller, animated: true)
646+
}
647+
648+
/// Presents a blocking view controller while variations are being fetched.
649+
///
650+
private func presentFetchingIndicator() {
651+
let inProgressViewController = InProgressViewController(viewProperties: .init(title: Localization.fetchingVariations, message: ""))
652+
present(inProgressViewController, animated: true)
653+
}
654+
655+
/// Presents a blocking view controller while variations are being created.
656+
///
657+
private func presentCreatingIndicator() {
658+
let newViewProperties = InProgressViewProperties(title: Localization.creatingVariations, message: "")
659+
660+
// There should be already a presented `InProgressViewController`. But we present one in case there isn;t.
661+
guard let inProgressViewController = self.presentedViewController as? InProgressViewController else {
662+
let inProgressViewController = InProgressViewController(viewProperties: newViewProperties)
663+
return present(inProgressViewController, animated: true)
664+
}
665+
666+
// Update the already presented view controller with the "Creating..." copy.
667+
inProgressViewController.updateViewProperties(newViewProperties)
668+
}
669+
670+
/// Dismiss any `InProgressViewController` being presented.
671+
///
672+
private func dismissBlockingIndicator() {
673+
if let inProgressViewController = self.presentedViewController as? InProgressViewController {
674+
inProgressViewController.dismiss(animated: true)
675+
}
643676
}
644677
}
645678

@@ -720,19 +753,19 @@ extension ProductVariationsViewController: SyncingCoordinatorDelegate {
720753
viewModel.generateAllVariations(for: product) { [weak self] currentState in
721754
switch currentState {
722755
case .fetching:
723-
break // TODO: Show fetching loading Indicator
756+
self?.presentFetchingIndicator()
724757
case .confirmation(let variationCount, let onCompletion):
725758
self?.presentGenerationConfirmation(numberOfVariations: variationCount, onCompletion: onCompletion)
726759
case .creating:
727-
break // TODO: Show creating loading Indicator
760+
self?.presentCreatingIndicator()
728761
case .canceled:
729-
break // TODO: Remove loading indicator
762+
self?.dismissBlockingIndicator()
730763
case .finished(let variationsCreated):
731-
// TODO: Remove loading indicator
764+
self?.dismissBlockingIndicator()
732765
// TODO: Inform about created variations
733766
break
734767
case .error(let error):
735-
// TODO: Remove loading indicator
768+
self?.dismissBlockingIndicator()
736769
self?.presentGenerationError(error)
737770
}
738771
}
@@ -852,6 +885,10 @@ private extension ProductVariationsViewController {
852885
}
853886
static let ok = NSLocalizedString("OK", comment: "Button text to confirm that we want to generate all variations")
854887
static let cancel = NSLocalizedString("Cancel", comment: "Button text to confirm that we don't want to generate all variations")
888+
static let fetchingVariations = NSLocalizedString("Fetching Variations...",
889+
comment: "Blocking indicator text when fetching existing variations prior generating them.")
890+
static let creatingVariations = NSLocalizedString("Creating Variations...",
891+
comment: "Blocking indicator text when creating multiple variations remotely.")
855892

856893
}
857894

0 commit comments

Comments
 (0)