mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-10-09 21:12:31 +02:00
ThreadView avoids double loading.
This commit is contained in:
@@ -50,10 +50,6 @@ abstract class FeedViewModel(val localFilter: FeedFilter<Note>): ViewModel() {
|
|||||||
return localFilter.loadTop()
|
return localFilter.loadTop()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearFeed() {
|
|
||||||
_feedContent.update { FeedState.Loading }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun refresh() {
|
fun refresh() {
|
||||||
val scope = CoroutineScope(Job() + Dispatchers.Default)
|
val scope = CoroutineScope(Job() + Dispatchers.Default)
|
||||||
scope.launch {
|
scope.launch {
|
||||||
|
@@ -32,6 +32,7 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.draw.drawBehind
|
import androidx.compose.ui.draw.drawBehind
|
||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.geometry.Offset
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.compositeOver
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import com.google.accompanist.swiperefresh.SwipeRefresh
|
import com.google.accompanist.swiperefresh.SwipeRefresh
|
||||||
@@ -48,6 +49,7 @@ import com.vitorpamplona.amethyst.ui.note.NoteUsernameDisplay
|
|||||||
import com.vitorpamplona.amethyst.ui.note.ReactionsRow
|
import com.vitorpamplona.amethyst.ui.note.ReactionsRow
|
||||||
import com.vitorpamplona.amethyst.ui.note.timeAgo
|
import com.vitorpamplona.amethyst.ui.note.timeAgo
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ThreadFeedView(noteId: String, viewModel: FeedViewModel, accountViewModel: AccountViewModel, navController: NavController) {
|
fun ThreadFeedView(noteId: String, viewModel: FeedViewModel, accountViewModel: AccountViewModel, navController: NavController) {
|
||||||
@@ -86,10 +88,18 @@ fun ThreadFeedView(noteId: String, viewModel: FeedViewModel, accountViewModel: A
|
|||||||
}
|
}
|
||||||
is FeedState.Loaded -> {
|
is FeedState.Loaded -> {
|
||||||
LaunchedEffect(noteId) {
|
LaunchedEffect(noteId) {
|
||||||
|
// waits to load the thread to scroll to item.
|
||||||
|
delay(100)
|
||||||
val noteForPosition = state.feed.value.filter { it.idHex == noteId}.firstOrNull()
|
val noteForPosition = state.feed.value.filter { it.idHex == noteId}.firstOrNull()
|
||||||
val position = state.feed.value.indexOf(noteForPosition)
|
var position = state.feed.value.indexOf(noteForPosition)
|
||||||
if (position > 0)
|
|
||||||
listState.animateScrollToItem(position, 0)
|
if (position >= 0) {
|
||||||
|
if (position >= 1 && position < state.feed.value.size - 1) {
|
||||||
|
position -- // show the replying note
|
||||||
|
}
|
||||||
|
|
||||||
|
listState.animateScrollToItem(position)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
|
@@ -30,7 +30,6 @@ fun ThreadScreen(noteId: String?, accountViewModel: AccountViewModel, navControl
|
|||||||
val feedViewModel: NostrThreadFeedViewModel = viewModel()
|
val feedViewModel: NostrThreadFeedViewModel = viewModel()
|
||||||
|
|
||||||
LaunchedEffect(noteId) {
|
LaunchedEffect(noteId) {
|
||||||
feedViewModel.clearFeed()
|
|
||||||
ThreadFeedFilter.loadThread(noteId)
|
ThreadFeedFilter.loadThread(noteId)
|
||||||
NostrThreadDataSource.loadThread(noteId)
|
NostrThreadDataSource.loadThread(noteId)
|
||||||
feedViewModel.invalidateData()
|
feedViewModel.invalidateData()
|
||||||
|
Reference in New Issue
Block a user