Skip to content

Add a check to avoid app crash when the products list is empty #11490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class DashboardBlazeViewModel @AssistedInject constructor(
val products = productsResult.getOrThrow()
val blazeCampaignModel = blazeCampaignResult.getOrThrow()

if (products.isEmpty()) {
// When the products is empty, the card will be hidden by the parent view model
// so we don't need to show any UI
return@combine null
}

when {
blazeCampaignModel == null -> showUiForNoCampaign(products)
else -> showUiForCampaign(blazeCampaignModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ class ObserveBlazeWidgetStatus @Inject constructor(
.withIndex()
.map { (index, productsCount) ->
if (productsCount == 0L && index == 0) {
productListRepository.fetchProductList().getOrNull()?.size != 0
productListRepository
.fetchProductList(
productFilterOptions = mapOf(ProductFilterOption.STATUS to ProductStatus.PUBLISH.value)
).getOrNull()
?.filterNot { it.isSampleProduct }
Comment on lines +41 to +44
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this issue while working on this, when the cached list is empty, I was fetching a new list from the API, but I was checking against the list of all products, and not just published non-sample products.

?.size != 0
} else {
productsCount > 0
}
Expand Down
Loading