Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/move-site-menu-items-to-viewmode…
Browse files Browse the repository at this point in the history
…l-slice' into move-site-menu-items-to-viewmodel-slice
  • Loading branch information
AjeshRPai committed Mar 22, 2024
2 parents b73b46d + 537ad6d commit 8120e49
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,28 @@ class DashboardCardsViewModelSlice @Inject constructor(
): List<MySiteCardAndItem> {
val cards = mutableListOf<MySiteCardAndItem>()
migrationSuccessCard?.let { cards.add(it) }
jpFullInstallFullPlugin?.let { cards.add(it) }
domainRegistrationCard?.let { cards.add(it) }
quicklinks?.let { cards.add(it) }
quickStart?.let { cards.add(it) }
blazeCard?.let { cards.add(it) }
plansCard?.let { cards.add(it) }
domainRegistrationCard?.let { cards.add(it) }
cardsState?.let {
if (cardsState is CardsState.Success) {
cards.addAll(cardsState.topCards)
}
}
bloganuaryNudgeCard?.let { cards.add(it) }
bloggingPromptCard?.let { cards.add(it) }
blazeCard?.let { cards.add(it) }
plansCard?.let { cards.add(it) }
cardsState?.let {
when (cardsState) {
is CardsState.Success -> cards.addAll(cardsState.cards)
is CardsState.Success -> {
cards.addAll(cardsState.cards)
cards.addAll(cardsState.bottomCards)
}
is CardsState.ErrorState -> cards.add(cardsState.error)
}
}
jpFullInstallFullPlugin?.let { cards.add(it) }
// when clearing the values of all child VM Slices,
// the no cards message will still be shown and hence we need to check if the personalize card
// is shown or not, if the personalize card is not shown, then it means that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,11 @@ class CardViewModelSlice @Inject constructor(
bottomDynamicCards: List<MySiteCardAndItem.Card>?
): CardsState {
val cards = mutableListOf<MySiteCardAndItem.Card>()
topDynamicCards?.let { cards.addAll(topDynamicCards) }
todaysStatsCard?.let { cards.add(todaysStatsCard) }
postsCard?.let { cards.addAll(postsCard) }
pagesCard?.let { cards.add(pagesCard) }
activityCard?.let { cards.add(activityCard) }
bottomDynamicCards?.let { cards.addAll(bottomDynamicCards) }
return CardsState.Success(cards)
return CardsState.Success(topDynamicCards ?: emptyList(), cards, bottomDynamicCards ?: emptyList())
}

private val _onNavigation = MutableLiveData<Event<SiteNavigationAction>>()
Expand Down Expand Up @@ -214,7 +212,10 @@ class CardViewModelSlice @Inject constructor(
}

private fun isUiModelEmpty(): Boolean {
return (uiModel.value is CardsState.Success) && (uiModel.value as CardsState.Success).cards.isEmpty()
return (uiModel.value is CardsState.Success)
&& (uiModel.value as CardsState.Success).topCards.isEmpty()
&& (uiModel.value as CardsState.Success).cards.isEmpty()
&& (uiModel.value as CardsState.Success).bottomCards.isEmpty()
}

private fun onDashboardErrorRetry() {
Expand All @@ -224,7 +225,7 @@ class CardViewModelSlice @Inject constructor(
fun postState(cards: List<CardModel>?) {
_isRefreshing.postValue(false)
if (cards.isNullOrEmpty()) {
uiModel.postValue(CardsState.Success(emptyList()))
uiModel.postValue(CardsState.Success(emptyList(), emptyList(), emptyList()))
return
}
scope.launch(bgDispatcher) {
Expand Down Expand Up @@ -256,7 +257,7 @@ class CardViewModelSlice @Inject constructor(
}

fun clearValue() {
uiModel.postValue(CardsState.Success(emptyList()))
uiModel.postValue(CardsState.Success(emptyList(), emptyList(), emptyList()))
collectJob?.cancel()
fetchJob?.cancel()
dynamicCardsViewModelSlice.clearValue()
Expand All @@ -280,6 +281,10 @@ class CardViewModelSlice @Inject constructor(
}

sealed class CardsState {
data class Success(val cards: List<MySiteCardAndItem.Card>) : CardsState()
data class Success(
val topCards: List<MySiteCardAndItem.Card>,
val cards: List<MySiteCardAndItem.Card>,
val bottomCards: List<MySiteCardAndItem.Card>
) : CardsState()
data class ErrorState(val error: MySiteCardAndItem) : CardsState()
}

0 comments on commit 8120e49

Please sign in to comment.