Skip to content

Commit 0e27835

Browse files
removed double apply mutation
1 parent 188468a commit 0e27835

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

app/src/main/java/com/cornellappdev/uplift/ui/viewmodels/nav/RootNavigationViewModel.kt

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,16 @@ class RootNavigationViewModel @Inject constructor(
6767
val hasSkipped = userInfoRepository.getSkipFromDataStore()
6868
val shouldShowHome = loggedIn || hasSkipped || !ONBOARDING_FLAG
6969
val newRoute = if (shouldShowHome) UpliftRootRoute.Home else UpliftRootRoute.Onboarding
70-
if (newRoute != uiStateFlow.value.startDestination || loggedIn != uiStateFlow.value.isLoggedIn) {
71-
applyMutation {
72-
copy(
73-
isLoggedIn = loggedIn,
74-
startDestination = newRoute,
75-
navEvent = UIEvent(newRoute)
76-
)
77-
}
78-
}
79-
else {
80-
applyMutation {
81-
copy(isLoggedIn = loggedIn)
82-
}
70+
71+
applyMutation {
72+
// Only attach a navEvent if we are actually changing the destination compared to what was set during initialization.
73+
val shouldNav = newRoute != startDestination || loggedIn != isLoggedIn
74+
75+
copy(
76+
isLoggedIn = loggedIn,
77+
startDestination = newRoute,
78+
navEvent = if (shouldNav) UIEvent(newRoute) else navEvent
79+
)
8380
}
8481
}
8582
}

0 commit comments

Comments
 (0)