Skip to content

Commit

Permalink
Rename Login navigation components to Auth (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb-livefront authored and vvolkgang committed Jun 20, 2024
1 parent c048d36 commit 915e9d5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.x8bit.bitwarden.ui.feature.login
package com.x8bit.bitwarden.ui.feature.auth

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
Expand All @@ -10,15 +10,15 @@ import com.x8bit.bitwarden.ui.feature.createaccount.navigateToCreateAccount
import com.x8bit.bitwarden.ui.feature.landing.LANDING_ROUTE
import com.x8bit.bitwarden.ui.feature.landing.landingDestination

const val LOGIN_ROUTE: String = "login"
const val AUTH_ROUTE: String = "auth"

/**
* Add login destinations to the nav graph.
* Add auth destinations to the nav graph.
*/
fun NavGraphBuilder.loginDestinations(navController: NavHostController) {
fun NavGraphBuilder.authDestinations(navController: NavHostController) {
navigation(
startDestination = LANDING_ROUTE,
route = LOGIN_ROUTE,
route = AUTH_ROUTE,
) {
createAccountDestinations()
landingDestination(
Expand All @@ -28,10 +28,10 @@ fun NavGraphBuilder.loginDestinations(navController: NavHostController) {
}

/**
* Navigate to the login screen. Note this will only work if login destination was added
* via [loginDestinations].
* Navigate to the auth screen. Note this will only work if auth destination was added
* via [authDestinations].
*/
fun NavController.navigateToLogin(
fun NavController.navigateToAuth(
navOptions: NavOptions? = null,
) {
navigate(LANDING_ROUTE, navOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navOptions
import com.x8bit.bitwarden.ui.components.PlaceholderComposable
import com.x8bit.bitwarden.ui.feature.login.loginDestinations
import com.x8bit.bitwarden.ui.feature.login.navigateToLogin
import com.x8bit.bitwarden.ui.feature.auth.authDestinations
import com.x8bit.bitwarden.ui.feature.auth.navigateToAuth

/**
* Controls root level [NavHost] for the app.
Expand All @@ -30,7 +30,7 @@ fun RootNavScreen(
startDestination = SplashRoute,
) {
splashDestinations()
loginDestinations(navController)
authDestinations(navController)
}

// When state changes, navigate to different root navigation state
Expand All @@ -41,7 +41,7 @@ fun RootNavScreen(
}
}
when (state) {
RootNavState.Login -> navController.navigateToLogin(rootNavOptions)
RootNavState.Auth -> navController.navigateToAuth(rootNavOptions)
RootNavState.Splash -> navController.navigateToSplash(rootNavOptions)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RootNavViewModel @Inject constructor() :
viewModelScope.launch {
@Suppress("MagicNumber")
delay(1000)
mutableStateFlow.value = RootNavState.Login
mutableStateFlow.value = RootNavState.Auth
}
}

Expand All @@ -32,9 +32,9 @@ class RootNavViewModel @Inject constructor() :
*/
sealed class RootNavState {
/**
* Show the login screen.
* Show the auth screens.
*/
data object Login : RootNavState()
data object Auth : RootNavState()

/**
* Show the splash screen.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class RootNavViewModelTests : BaseViewModelTest() {
}

@Test
fun `state should move from splash to login`() = runTest {
fun `state should move from splash to auth`() = runTest {
val viewModel = RootNavViewModel()
viewModel.stateFlow.test {
assert(awaitItem() is RootNavState.Splash)
assert(awaitItem() is RootNavState.Login)
assert(awaitItem() is RootNavState.Auth)
}
}
}

0 comments on commit 915e9d5

Please sign in to comment.