refactor: harden main shell state

This commit is contained in:
Codex
2026-05-14 17:51:48 +03:00
parent 22d13fcbe5
commit 3bb4de24a7
3 changed files with 16 additions and 8 deletions
@@ -82,6 +82,10 @@ class MainViewModelImpl(
private var openNotificationsSettings = false
private var openAppSettings = false
init {
listenLongPollState()
}
override fun onError(error: BaseError) {
when (error) {
BaseError.SessionExpired,
@@ -205,8 +209,6 @@ class MainViewModelImpl(
Log.d("MainViewModel", "currentAccount: $currentAccount")
listenLongPollState()
if (currentAccount != null) {
UserConfig.apply {
this.userId = currentAccount.userId
@@ -45,6 +45,7 @@ import dev.meloda.fast.friends.navigation.friendsScreen
import dev.meloda.fast.model.BaseError
import dev.meloda.fast.model.BottomNavigationItem
import dev.meloda.fast.navigation.MainGraph
import dev.meloda.fast.profile.navigation.Profile
import dev.meloda.fast.profile.navigation.profileScreen
import dev.meloda.fast.ui.theme.LocalBottomPadding
import dev.meloda.fast.ui.theme.LocalHazeState
@@ -69,15 +70,18 @@ fun MainScreen(
val theme = LocalThemeConfig.current
val hazeState = remember { HazeState(true) }
val navController = rememberNavController()
var selectedItemIndex by rememberSaveable {
mutableIntStateOf(1)
val defaultTabIndex = remember(navigationItems) {
navigationItems.indexOfFirst { it.route == ConvoGraph }.takeIf { it >= 0 } ?: 0
}
BackHandler(enabled = selectedItemIndex != 1) {
var selectedItemIndex by rememberSaveable {
mutableIntStateOf(defaultTabIndex)
}
BackHandler(enabled = selectedItemIndex != defaultTabIndex) {
val currentRoute = navigationItems[selectedItemIndex].route
selectedItemIndex = 1
selectedItemIndex = defaultTabIndex
navController.navigate(navigationItems[selectedItemIndex].route) {
popUpTo(route = currentRoute) {
inclusive = true
@@ -127,7 +131,7 @@ fun MainScreen(
}
},
icon = {
if (index == navigationItems.size - 1) {
if (item.route == Profile) {
var isLoading by remember {
mutableStateOf(true)
}
@@ -24,6 +24,8 @@ object UserConfig {
accessToken = ""
fastToken = ""
userId = -1
trustedHash = null
exchangeToken = null
}
fun isLoggedIn(): Boolean {