1+ import Combine
12import Yosemite
23import protocol WooFoundation. Analytics
34
@@ -15,6 +16,10 @@ final class ProductSearchUICommand: SearchUICommand {
1516
1617 let cancelButtonAccessibilityIdentifier = " product-search-screen-cancel-button "
1718
19+ var reloadUIRequests : AnyPublisher < Void , Never > {
20+ reloadUINeeded. eraseToAnyPublisher ( )
21+ }
22+
1823 var resynchronizeModels : ( ( ) -> Void ) = { }
1924
2025 private var lastSearchQueryByFilter : [ ProductSearchFilter : String ] = [ : ]
@@ -27,6 +32,12 @@ final class ProductSearchUICommand: SearchUICommand {
2732 private let onProductSelection : ( Product ) -> Void
2833 private let onCancel : ( ) -> Void
2934
35+ private let imageUploader = ServiceLocator . productImageUploader
36+ private var activeUploadIds : [ Int64 ] = [ ]
37+ private var activeUploadSubscription : AnyCancellable ?
38+
39+ private let reloadUINeeded = PassthroughSubject < Void , Never > ( )
40+
3041 init ( siteID: Int64 ,
3142 stores: StoresManager = ServiceLocator . stores,
3243 analytics: Analytics = ServiceLocator . analytics,
@@ -39,6 +50,8 @@ final class ProductSearchUICommand: SearchUICommand {
3950 self . isSearchProductsBySKUEnabled = isSearchProductsBySKUEnabled
4051 self . onProductSelection = onProductSelection
4152 self . onCancel = onCancel
53+
54+ observePendingImageUploads ( )
4255 }
4356
4457 func createResultsController( ) -> ResultsController < ResultsControllerModel > {
@@ -98,7 +111,8 @@ final class ProductSearchUICommand: SearchUICommand {
98111 }
99112
100113 func createCellViewModel( model: Product ) -> ProductsTabProductViewModel {
101- ProductsTabProductViewModel ( product: model, isSKUShown: true )
114+ let hasPendingUploads = activeUploadIds. contains ( where: { $0 == model. productID } )
115+ return ProductsTabProductViewModel ( product: model, hasPendingUploads: hasPendingUploads, isSKUShown: true )
102116 }
103117
104118 /// Synchronizes the Products matching a given Keyword
@@ -163,6 +177,17 @@ final class ProductSearchUICommand: SearchUICommand {
163177}
164178
165179private extension ProductSearchUICommand {
180+ func observePendingImageUploads( ) {
181+ activeUploadSubscription = imageUploader. activeUploads
182+ . sink { [ weak self] keys in
183+ guard let self else { return }
184+ activeUploadIds = keys
185+ . filter { $0. siteID == self . siteID }
186+ . map { $0. productOrVariationID. id }
187+ reloadUINeeded. send ( ( ) )
188+ }
189+ }
190+
166191 func showResults( filter: ProductSearchFilter ) {
167192 guard filter != self . filter else {
168193 return
0 commit comments