Skip to content

Commit

Permalink
Rename : BriefingArticleUiState -> BriefingCategoryArticleUiState
Browse files Browse the repository at this point in the history
  • Loading branch information
DongChyeon committed Jun 18, 2024
1 parent 431138b commit 0000b71
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ internal fun HomeScreen(

val isRefreshing = uiState.articles[categories[pagerState.currentPage].category]?.let {
when (it) {
is BriefingArticleUiState.Loading -> true
is BriefingCategoryArticleUiState.Loading -> true
else -> false
}
} ?: false
Expand All @@ -160,13 +160,13 @@ internal fun HomeScreen(
},
updatedAt = uiState.articles[categories[page].category]?.let {
when (it) {
is BriefingArticleUiState.Success -> it.categoryArticles.createdAt
is BriefingCategoryArticleUiState.Success -> it.categoryArticles.createdAt
else -> null
}
},
articles = uiState.articles[categories[page].category]?.let {
when (it) {
is BriefingArticleUiState.Success -> it.categoryArticles.briefings
is BriefingCategoryArticleUiState.Success -> it.categoryArticles.briefings
else -> emptyList()
}
} ?: emptyList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ sealed class HomeEvent {
}

data class HomeUiState(
val articles: HashMap<BriefingArticleCategory, BriefingArticleUiState>
val articles: HashMap<BriefingArticleCategory, BriefingCategoryArticleUiState>
)

sealed interface BriefingArticleUiState {
data object None : BriefingArticleUiState
data class Success(val categoryArticles: BriefingCategoryArticles) : BriefingArticleUiState
data object Error : BriefingArticleUiState
data object Loading : BriefingArticleUiState
sealed interface BriefingCategoryArticleUiState {
data object None : BriefingCategoryArticleUiState
data class Success(val categoryArticles: BriefingCategoryArticles) : BriefingCategoryArticleUiState
data object Error : BriefingCategoryArticleUiState
data object Loading : BriefingCategoryArticleUiState
}

@HiltViewModel
Expand All @@ -41,10 +41,10 @@ class HomeViewModel @Inject constructor(
private val _uiState: MutableStateFlow<HomeUiState> = MutableStateFlow(
HomeUiState(
articles = hashMapOf(
BriefingArticleCategory.SOCIAL to BriefingArticleUiState.None,
BriefingArticleCategory.SCIENCE to BriefingArticleUiState.None,
BriefingArticleCategory.GLOBAL to BriefingArticleUiState.None,
BriefingArticleCategory.ECONOMY to BriefingArticleUiState.None
BriefingArticleCategory.SOCIAL to BriefingCategoryArticleUiState.None,
BriefingArticleCategory.SCIENCE to BriefingCategoryArticleUiState.None,
BriefingArticleCategory.GLOBAL to BriefingCategoryArticleUiState.None,
BriefingArticleCategory.ECONOMY to BriefingCategoryArticleUiState.None
)
)
)
Expand All @@ -57,8 +57,8 @@ class HomeViewModel @Inject constructor(
category: BriefingArticleCategory,
isRefresh: Boolean
) = viewModelScope.launch {
val isLoading = _uiState.value.articles[category] is BriefingArticleUiState.Loading
val isLoaded = _uiState.value.articles[category] is BriefingArticleUiState.Success
val isLoading = _uiState.value.articles[category] is BriefingCategoryArticleUiState.Loading
val isLoaded = _uiState.value.articles[category] is BriefingCategoryArticleUiState.Success

if (isLoading || (isLoaded && !isRefresh)) {
return@launch
Expand All @@ -70,15 +70,15 @@ class HomeViewModel @Inject constructor(
_uiState.update {
it.copy(
articles = HashMap(it.articles.toMutableMap().apply {
this[category] = BriefingArticleUiState.Loading
this[category] = BriefingCategoryArticleUiState.Loading
})
)
}
}.collect { summaries ->
_uiState.update {
it.copy(
articles = HashMap(it.articles.toMutableMap().apply {
this[category] = BriefingArticleUiState.Success(
this[category] = BriefingCategoryArticleUiState.Success(
categoryArticles = summaries
)
})
Expand Down

0 comments on commit 0000b71

Please sign in to comment.