Skip to content

Commit

Permalink
refactor/#78 : 얼리 리턴으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwon12 committed Feb 19, 2025
1 parent d5d9768 commit 64196ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/yapp/app/official/ui/Navigator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import androidx.navigation.NavDestination
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.yapp.feature.home.navigation.HomeRoute
import com.yapp.feature.home.navigation.navigateToHome
import com.yapp.feature.home.navigation.navigateToSetting
import com.yapp.feature.login.navigation.LoginRoute
import com.yapp.feature.login.navigation.navigateToLogin
import com.yapp.feature.notice.navigation.navigateToNotice
import com.yapp.feature.signup.navigation.navigateToSignUp
Expand All @@ -31,7 +31,7 @@ class NavigatorState(
@Composable get() = navController
.currentBackStackEntryAsState().value?.destination

val startDestination = HomeRoute
val startDestination = LoginRoute

fun navigateLoginScreen() {
navController.navigateToLogin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,39 +84,39 @@ class LoginViewModel @Inject constructor(
reduce: (LoginState.() -> LoginState) -> Unit,
postSideEffect: (LoginSideEffect) -> Unit,
) {
if (!email.matches(Regex.email)){
if (!email.matches(Regex.email)) {
reduce {
copy(
isLoginEnabled = false,
emailErrorDescription = "입력하신 이메일을 확인해주세요.",
passwordErrorDescription = null
)
}
}else{
viewModelScope.launch {
loginUseCase(email, password)
.onSuccess {
postSideEffect(LoginSideEffect.NavigateToHome)
}
.onFailure {
val errorMessage = it.message ?: ""
reduce{copy(isLoginEnabled = false)}
when (it) {
is InvalidRequestArgument -> {
reduce {
copy(
emailErrorDescription = null,
passwordErrorDescription = "비밀번호가 달라요. 입력하신 비밀번호를 확인해주세요."
)
}
}
else -> {
postSideEffect(LoginSideEffect.ShowToast(errorMessage))
return
}
viewModelScope.launch {
loginUseCase(email, password)
.onSuccess {
postSideEffect(LoginSideEffect.NavigateToHome)
}
.onFailure {
val errorMessage = it.message ?: ""
reduce { copy(isLoginEnabled = false) }
when (it) {
is InvalidRequestArgument -> {
reduce {
copy(
emailErrorDescription = null,
passwordErrorDescription = "비밀번호가 달라요. 입력하신 비밀번호를 확인해주세요."
)
}
}
}
}

else -> {
postSideEffect(LoginSideEffect.ShowToast(errorMessage))
}
}
}
}
}
}
Expand Down

0 comments on commit 64196ee

Please sign in to comment.