Fixed recomposition logic when toggling favorites filter

This commit is contained in:
Sad Ellie 2023-04-05 21:57:29 +03:00
parent 89036b6ea6
commit c5e0291789
2 changed files with 7 additions and 6 deletions

View File

@ -64,7 +64,7 @@ import com.sadellie.unitto.feature.unitslist.components.UnitListItem
@Composable
internal fun LeftSideScreen(
viewModel: UnitsListViewModel,
currentUnitId: String,
currentUnitId: String?,
navigateUp: () -> Unit,
navigateToSettingsAction: () -> Unit,
selectAction: (AbstractUnit) -> Unit
@ -142,8 +142,11 @@ internal fun LeftSideScreen(
}
}
// This block is called only once on initial composition
LaunchedEffect(uiState.value.shownUnitGroups) {
LaunchedEffect(uiState.value.shownUnitGroups, currentUnitId) {
if (currentUnitId == null) return@LaunchedEffect
// This is still wrong, but works good enough.
// Ideally we shouldn't use uiState.value.shownUnitGroups
viewModel.setSelectedChip(currentUnitId)
val groupToSelect = uiState.value.shownUnitGroups.indexOf(uiState.value.chosenUnitGroup)
if (groupToSelect > -1) {
chipsRowLazyListState.animateScrollToItem(groupToSelect)

View File

@ -50,11 +50,9 @@ fun NavGraphBuilder.leftScreen(
composable(
route = "$leftSideRoute/{$unitFromIdArg}"
) {
val unitFromId = it.arguments?.getString(unitFromIdArg) ?: return@composable
viewModel.setSelectedChip(unitFromId)
LeftSideScreen(
viewModel = viewModel,
currentUnitId = unitFromId,
currentUnitId = it.arguments?.getString(unitFromIdArg),
navigateUp = navigateUp,
navigateToSettingsAction = navigateToUnitGroups,
selectAction = onSelect