Minor refactoring

This commit is contained in:
Vitor Pamplona
2025-08-14 15:43:43 -04:00
parent dfe5f86a23
commit ba27b68c14
2 changed files with 9 additions and 8 deletions
@@ -50,7 +50,7 @@ class FeedContentState(
// Simple counter that changes when it needs to invalidate everything // Simple counter that changes when it needs to invalidate everything
private val _scrollToTop = MutableStateFlow<Int>(0) private val _scrollToTop = MutableStateFlow<Int>(0)
val scrollToTop = _scrollToTop.asStateFlow() val scrollToTop = _scrollToTop.asStateFlow()
var scrolltoTopPending = false var scrollToTopPending = false
private var lastFeedKey: Any? = null private var lastFeedKey: Any? = null
@@ -59,14 +59,14 @@ class FeedContentState(
val lastNoteCreatedAtWhenFullyLoaded = MutableStateFlow<Long?>(null) val lastNoteCreatedAtWhenFullyLoaded = MutableStateFlow<Long?>(null)
fun sendToTop() { fun sendToTop() {
if (scrolltoTopPending) return if (scrollToTopPending) return
scrolltoTopPending = true scrollToTopPending = true
viewModelScope.launch(Dispatchers.IO) { _scrollToTop.emit(_scrollToTop.value + 1) } viewModelScope.launch(Dispatchers.IO) { _scrollToTop.emit(_scrollToTop.value + 1) }
} }
suspend fun sentToTop() { suspend fun sentToTop() {
scrolltoTopPending = false scrollToTopPending = false
} }
private fun refresh() { private fun refresh() {
@@ -128,7 +128,8 @@ class FeedContentState(
fun deleteFromFeed(deletedNotes: Set<Note>) { fun deleteFromFeed(deletedNotes: Set<Note>) {
val feed = _feedContent.value val feed = _feedContent.value
if (feed is FeedState.Loaded) { if (feed is FeedState.Loaded) {
updateFeed((feed.feed.value.list - deletedNotes).toImmutableList()) val notes = (feed.feed.value.list - deletedNotes).toImmutableList()
updateFeed(notes)
} }
} }
@@ -37,7 +37,7 @@ fun WatchScrollToTop(
val scrollToTop by feedContentState.scrollToTop.collectAsStateWithLifecycle() val scrollToTop by feedContentState.scrollToTop.collectAsStateWithLifecycle()
LaunchedEffect(scrollToTop) { LaunchedEffect(scrollToTop) {
if (scrollToTop > 0 && feedContentState.scrolltoTopPending) { if (scrollToTop > 0 && feedContentState.scrollToTopPending) {
listState.scrollToItem(index = 0) listState.scrollToItem(index = 0)
feedContentState.sentToTop() feedContentState.sentToTop()
} }
@@ -52,7 +52,7 @@ fun WatchScrollToTop(
val scrollToTop by feedContentState.scrollToTop.collectAsStateWithLifecycle() val scrollToTop by feedContentState.scrollToTop.collectAsStateWithLifecycle()
LaunchedEffect(scrollToTop) { LaunchedEffect(scrollToTop) {
if (scrollToTop > 0 && feedContentState.scrolltoTopPending) { if (scrollToTop > 0 && feedContentState.scrollToTopPending) {
listState.scrollToItem(index = 0) listState.scrollToItem(index = 0)
feedContentState.sentToTop() feedContentState.sentToTop()
} }
@@ -82,7 +82,7 @@ fun WatchScrollToTop(
val scrollToTop by videoFeedContentState.scrollToTop.collectAsStateWithLifecycle() val scrollToTop by videoFeedContentState.scrollToTop.collectAsStateWithLifecycle()
LaunchedEffect(scrollToTop) { LaunchedEffect(scrollToTop) {
if (scrollToTop > 0 && videoFeedContentState.scrolltoTopPending) { if (scrollToTop > 0 && videoFeedContentState.scrollToTopPending) {
pagerState.scrollToPage(page = 0) pagerState.scrollToPage(page = 0)
videoFeedContentState.sentToTop() videoFeedContentState.sentToTop()
} }