ChatRouter: Remember last selected channel

This change ensures that the last selected channel remains highlighted
in the channel list even when navigating to other screens like server
settings.

The `lastSelectedChannelId` is updated whenever a channel destination
is navigated to. This stored ID is then used to determine the
`selectedChannelId` for the `ServerChannels` composable, ensuring
the correct channel remains visually selected.
This commit is contained in:
AbronStudio 2025-09-07 10:41:00 +03:30
parent da28d50b18
commit b1eb411ad4
1 changed files with 4 additions and 1 deletions

View File

@ -164,6 +164,7 @@ class ChatRouterViewModel @Inject constructor(
var currentDestination by mutableStateOf<ChatRouterDestination>(ChatRouterDestination.default)
var previousDestination by mutableStateOf<ChatRouterDestination?>(null)
var lastNonChannelDestination by mutableStateOf<ChatRouterDestination?>(null)
var lastSelectedChannelId by mutableStateOf<String?>(null)
var latestChangelogRead by mutableStateOf(true)
var latestChangelog by mutableStateOf("")
var latestChangelogBody by mutableStateOf("")
@ -226,6 +227,8 @@ class ChatRouterViewModel @Inject constructor(
currentDestination = destination
if (destination !is ChatRouterDestination.Channel) {
lastNonChannelDestination = destination
} else {
lastSelectedChannelId = destination.channelId
}
}
}
@ -1105,7 +1108,7 @@ fun ChannelNavigator(
is ChatRouterDestination.Channel -> currentServer
else -> null
},
selectedChannelId = (if (dest is ChatRouterDestination.Channel) dest.channelId else null),
selectedChannelId = viewModel.lastSelectedChannelId,
navigateToServer = viewModel::navigateToServer,
onShowServerContextSheet = onShowServerContextSheet,
showSettingsIcon = isTouchExplorationEnabled,