mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-29 06:52:50 +02:00
Minor refactoring
This commit is contained in:
@@ -50,7 +50,7 @@ class FeedContentState(
|
||||
// Simple counter that changes when it needs to invalidate everything
|
||||
private val _scrollToTop = MutableStateFlow<Int>(0)
|
||||
val scrollToTop = _scrollToTop.asStateFlow()
|
||||
var scrolltoTopPending = false
|
||||
var scrollToTopPending = false
|
||||
|
||||
private var lastFeedKey: Any? = null
|
||||
|
||||
@@ -59,14 +59,14 @@ class FeedContentState(
|
||||
val lastNoteCreatedAtWhenFullyLoaded = MutableStateFlow<Long?>(null)
|
||||
|
||||
fun sendToTop() {
|
||||
if (scrolltoTopPending) return
|
||||
if (scrollToTopPending) return
|
||||
|
||||
scrolltoTopPending = true
|
||||
scrollToTopPending = true
|
||||
viewModelScope.launch(Dispatchers.IO) { _scrollToTop.emit(_scrollToTop.value + 1) }
|
||||
}
|
||||
|
||||
suspend fun sentToTop() {
|
||||
scrolltoTopPending = false
|
||||
scrollToTopPending = false
|
||||
}
|
||||
|
||||
private fun refresh() {
|
||||
@@ -128,7 +128,8 @@ class FeedContentState(
|
||||
fun deleteFromFeed(deletedNotes: Set<Note>) {
|
||||
val feed = _feedContent.value
|
||||
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()
|
||||
|
||||
LaunchedEffect(scrollToTop) {
|
||||
if (scrollToTop > 0 && feedContentState.scrolltoTopPending) {
|
||||
if (scrollToTop > 0 && feedContentState.scrollToTopPending) {
|
||||
listState.scrollToItem(index = 0)
|
||||
feedContentState.sentToTop()
|
||||
}
|
||||
@@ -52,7 +52,7 @@ fun WatchScrollToTop(
|
||||
val scrollToTop by feedContentState.scrollToTop.collectAsStateWithLifecycle()
|
||||
|
||||
LaunchedEffect(scrollToTop) {
|
||||
if (scrollToTop > 0 && feedContentState.scrolltoTopPending) {
|
||||
if (scrollToTop > 0 && feedContentState.scrollToTopPending) {
|
||||
listState.scrollToItem(index = 0)
|
||||
feedContentState.sentToTop()
|
||||
}
|
||||
@@ -82,7 +82,7 @@ fun WatchScrollToTop(
|
||||
val scrollToTop by videoFeedContentState.scrollToTop.collectAsStateWithLifecycle()
|
||||
|
||||
LaunchedEffect(scrollToTop) {
|
||||
if (scrollToTop > 0 && videoFeedContentState.scrolltoTopPending) {
|
||||
if (scrollToTop > 0 && videoFeedContentState.scrollToTopPending) {
|
||||
pagerState.scrollToPage(page = 0)
|
||||
videoFeedContentState.sentToTop()
|
||||
}
|
||||
|
Reference in New Issue
Block a user