Skip to content

Commit 964615c

Browse files
committed
Improve readability for updating a product remotely.
1 parent 3b900ae commit 964615c

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

WooCommerce/Classes/ViewRelated/Products/Edit Product/ProductFormViewController.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ private extension ProductFormViewController {
169169

170170
navigationController?.present(inProgressViewController, animated: true, completion: nil)
171171

172+
updateProductRemotely()
173+
}
174+
175+
func updateProductRemotely() {
176+
waitUntilAllImagesAreUploaded { [weak self] in
177+
self?.dispatchUpdateProductAction()
178+
}
179+
}
180+
181+
func waitUntilAllImagesAreUploaded(onCompletion: @escaping () -> Void) {
172182
let group = DispatchGroup()
173183

174184
// Waits for all product images to be uploaded before updating the product remotely.
@@ -186,13 +196,13 @@ private extension ProductFormViewController {
186196
group.leave()
187197
}
188198

189-
group.notify(queue: .main) { [weak self] in
199+
group.notify(queue: .main) {
190200
observationToken.cancel()
191-
self?.updateProductRemotely()
201+
onCompletion()
192202
}
193203
}
194204

195-
func updateProductRemotely() {
205+
func dispatchUpdateProductAction() {
196206
let action = ProductAction.updateProduct(product: product) { [weak self] (product, error) in
197207
guard let product = product, error == nil else {
198208
let errorDescription = error?.localizedDescription ?? "No error specified"

0 commit comments

Comments
 (0)