Skip to content

Commit

Permalink
fix loading state issue for first time search
Browse files Browse the repository at this point in the history
  • Loading branch information
momintahir committed Mar 26, 2024
1 parent 257266b commit a3502e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import org.jetbrains.compose.resources.painterResource

@Composable
fun NewsList(
articles: List<Article>,
articles: List<Article>?,
savedNews: List<Article>? = null,
onItemClick: (String) -> Unit,
showSaveIcon: Boolean,
Expand All @@ -47,16 +47,19 @@ fun NewsList(
verticalArrangement = Arrangement.Top,
contentPadding = PaddingValues(bottom = 70.dp)
) {
itemsIndexed(articles) { index, article ->
NewsItem(
article = article,
showSaveIcon = showSaveIcon,
isSelected = savedNews?.contains(article) == true,
onClick = { onItemClick(article.url) },
onActionSave = {
onActionSave(article, index) },
onActionRemove = {onActionRemove(article, index)}
)
if (articles != null) {
itemsIndexed(articles) { index, article ->
NewsItem(
article = article,
showSaveIcon = showSaveIcon,
isSelected = savedNews?.contains(article) == true,
onClick = { onItemClick(article.url) },
onActionSave = {
onActionSave(article, index)
},
onActionRemove = { onActionRemove(article, index) }
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@ class SearchNewsScreen : Screen {
search = it
viewModel.onSearchTextChange(it)
})
val news = viewModel.search.collectAsState().value ?: return
val news = viewModel.search.collectAsState().value
val isSearching = viewModel.isSearching.collectAsState().value

Spacer(Modifier.height(20.dp))
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
NewsList(news.articles, onActionSave = { article, _ ->
NewsList(news?.articles, onActionSave = { article, _ ->
viewModel.saveArticle(article) }, onItemClick = { navigateToWebViewScreen(it, navigator) }, showSaveIcon = true)
if (isSearching) {
println("isSearching $isSearching")
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
CircularProgressIndicator(modifier = Modifier.align(Alignment.TopCenter))
}
}
}
Expand Down

0 comments on commit a3502e5

Please sign in to comment.