Skip to content

Commit

Permalink
[chore/#10] Loading State로 설정하는 위치를 변경합니다.
Browse files Browse the repository at this point in the history
  • Loading branch information
SYAAINN committed Dec 4, 2024
1 parent 797bbda commit 66a5a90
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ class AuthViewModel @Inject constructor(
val signUpState: StateFlow<SignUpState> = _signUpState

fun validateSignIn(username: String, password: String) {
_signInState.value = SignInState.Loading
viewModelScope.launch {
_signInState.value = SignInState.Loading
val result = authRepository.login(username = username, password = password)
_signInState.value = result.fold(
onSuccess = { token ->
tokenRepository.setToken(token.token)
Log.d("token", "토큰 저장 완료! 저장값은 ${token.token} 입니다.")
SignInState.Success(token)
},
onFailure = {
Expand All @@ -44,8 +43,8 @@ class AuthViewModel @Inject constructor(
}

fun validateSignUp(username: String, password: String, hobby: String) {
_signUpState.value = SignUpState.Loading
viewModelScope.launch {
_signUpState.value = SignUpState.Loading
val result = authRepository.registerUser(
user = User(
username = username,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ class MainViewModel @Inject constructor(
private val _hobbySearchState = MutableStateFlow<HobbySearchState>(HobbySearchState.Idle)
val hobbySearchState: StateFlow<HobbySearchState> = _hobbySearchState

private val _userInfoUpdateState = MutableStateFlow<UserInfoUpdateState>(UserInfoUpdateState.Idle)
private val _userInfoUpdateState =
MutableStateFlow<UserInfoUpdateState>(UserInfoUpdateState.Idle)
val userInfoUpdateState: StateFlow<UserInfoUpdateState> = _userInfoUpdateState

fun getUserHobby() {
_userHobbyState.value = UserHobbyState.Loading
viewModelScope.launch {
_userHobbyState.value = UserHobbyState.Loading
val result = userRepository.getMyHobby(token = token)
_userHobbyState.value = result.fold(
onSuccess = {
Expand All @@ -42,8 +43,8 @@ class MainViewModel @Inject constructor(
}

fun getOthersHobby(userNo: String) {
_hobbySearchState.value = HobbySearchState.Loading
viewModelScope.launch {
_hobbySearchState.value = HobbySearchState.Loading
val result = userRepository.getOthersHobby(
token = token,
userNo = userNo.toInt()
Expand All @@ -60,8 +61,8 @@ class MainViewModel @Inject constructor(
}

fun updateUserInfo(password: String?, hobby: String?) {
_userInfoUpdateState.value = UserInfoUpdateState.Loading
viewModelScope.launch {
_userInfoUpdateState.value = UserInfoUpdateState.Loading
val result = userRepository.updateUserInfo(
token = token,
password = password,
Expand Down

0 comments on commit 66a5a90

Please sign in to comment.