diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/HomePresenter.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/HomePresenter.kt index 651931ed4..306360e57 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/HomePresenter.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/HomePresenter.kt @@ -58,6 +58,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged +import kotlinx.coroutines.flow.distinctUntilChangedBy import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.map @@ -263,17 +264,17 @@ class HomePresenter( } } - rssRepository.featuredPosts( - selectedFeedId = activeSource?.id, - unreadOnly = unreadOnly, - after = postsAfter - ) + rssRepository + .featuredPosts( + selectedFeedId = activeSource?.id, + unreadOnly = unreadOnly, + after = postsAfter + ) + .map { Triple(it, postsType, activeSource) } } - .distinctUntilChanged() - .onEach { featuredPosts -> + .distinctUntilChangedBy { (featuredPosts, _, _) -> featuredPosts } + .onEach { (featuredPosts, postsType, activeSource) -> val featuredPostIds = featuredPosts.map { it.id } - val postsType = _state.value.postsType - val activeSource = _state.value.activeSource val unreadOnly = when (postsType) { diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/HomeScreen.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/HomeScreen.kt index 739998df1..3aa175653 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/HomeScreen.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/HomeScreen.kt @@ -114,6 +114,7 @@ internal fun HomeScreen(homePresenter: HomePresenter, modifier: Modifier = Modif val listState = rememberLazyListState() val featuredPostsPagerState = rememberPagerState(pageCount = { state.featuredPosts?.size ?: 0 }) + val showScrollToTop by remember { derivedStateOf { listState.firstVisibleItemIndex > 1 } } val strings = LocalStrings.current val linkHandler = LocalLinkHandler.current @@ -144,7 +145,6 @@ internal fun HomeScreen(homePresenter: HomePresenter, modifier: Modifier = Modif val sheetPeekHeight = BOTTOM_SHEET_PEEK_HEIGHT + WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding() - val showScrollToTop by remember { derivedStateOf { listState.firstVisibleItemIndex > 0 } } BottomSheetScaffold( modifier = diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/PostList.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/PostList.kt index a22cd8d94..26758329a 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/PostList.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/home/ui/PostList.kt @@ -90,18 +90,20 @@ internal fun PostsList( state = listState, contentPadding = PaddingValues(top = topContentPadding, bottom = 128.dp) ) { - item { - FeaturedSection( - paddingValues = paddingValues, - pagerState = featuredPostsPagerState, - featuredPosts = featuredPosts, - featuredItemBlurEnabled = featuredItemBlurEnabled, - onItemClick = onPostClicked, - onPostBookmarkClick = onPostBookmarkClick, - onPostCommentsClick = onPostCommentsClick, - onPostSourceClick = onPostSourceClick, - onTogglePostReadClick = onTogglePostReadClick - ) + if (featuredPosts.isNotEmpty()) { + item { + FeaturedSection( + paddingValues = paddingValues, + pagerState = featuredPostsPagerState, + featuredPosts = featuredPosts, + featuredItemBlurEnabled = featuredItemBlurEnabled, + onItemClick = onPostClicked, + onPostBookmarkClick = onPostBookmarkClick, + onPostCommentsClick = onPostCommentsClick, + onPostSourceClick = onPostSourceClick, + onTogglePostReadClick = onTogglePostReadClick + ) + } } items(posts.itemCount) { index ->