Fixes the update of the feed after adding an image on stories.

This commit is contained in:
Vitor Pamplona
2023-08-20 21:24:57 -04:00
parent 844f7cd478
commit 0e6a2c339e
2 changed files with 10 additions and 10 deletions

View File

@@ -48,7 +48,7 @@ import kotlinx.coroutines.withContext
@OptIn(ExperimentalPermissionsApi::class)
@Composable
fun NewImageButton(accountViewModel: AccountViewModel, nav: (String) -> Unit) {
fun NewImageButton(accountViewModel: AccountViewModel, nav: (String) -> Unit, navScrollToTop: (Route, Boolean) -> Unit) {
var wantsToPost by remember {
mutableStateOf(false)
}
@@ -62,11 +62,9 @@ fun NewImageButton(accountViewModel: AccountViewModel, nav: (String) -> Unit) {
val postViewModel: NewMediaModel = viewModel()
postViewModel.onceUploaded {
scope.launch(Dispatchers.Default) {
// awaits an refresh on the list
delay(250)
delay(500)
withContext(Dispatchers.Main) {
val route = Route.Video.route.replace("{scrollToTop}", "true")
nav(route)
navScrollToTop(Route.Video, true)
}
}
}

View File

@@ -217,7 +217,7 @@ fun MainScreen(
}
},
floatingActionButton = {
FloatingButtons(navState, accountViewModel, accountStateViewModel, nav)
FloatingButtons(navState, accountViewModel, accountStateViewModel, nav, navBottomRow)
},
scaffoldState = scaffoldState
) {
@@ -247,7 +247,8 @@ fun FloatingButtons(
navEntryState: State<NavBackStackEntry?>,
accountViewModel: AccountViewModel,
accountStateViewModel: AccountStateViewModel,
nav: (String) -> Unit
nav: (String) -> Unit,
navScrollToTop: (Route, Boolean) -> Unit
) {
val accountState by accountStateViewModel.accountContent.collectAsState()
@@ -260,7 +261,7 @@ fun FloatingButtons(
// Does nothing.
}
is AccountState.LoggedIn -> {
WritePermissionButtons(navEntryState, accountViewModel, nav)
WritePermissionButtons(navEntryState, accountViewModel, nav, navScrollToTop)
}
}
}
@@ -270,7 +271,8 @@ fun FloatingButtons(
private fun WritePermissionButtons(
navEntryState: State<NavBackStackEntry?>,
accountViewModel: AccountViewModel,
nav: (String) -> Unit
nav: (String) -> Unit,
navScrollToTop: (Route, Boolean) -> Unit
) {
val currentRoute by remember(navEntryState.value) {
derivedStateOf {
@@ -281,7 +283,7 @@ private fun WritePermissionButtons(
when (currentRoute) {
Route.Home.base -> NewNoteButton(accountViewModel, nav)
Route.Message.base -> ChannelFabColumn(accountViewModel, nav)
Route.Video.base -> NewImageButton(accountViewModel, nav)
Route.Video.base -> NewImageButton(accountViewModel, nav, navScrollToTop)
Route.Community.base -> {
val communityId by remember(navEntryState.value) {
derivedStateOf {