Skip to content

Commit

Permalink
[fix] : uistate util로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
chanubc committed Jan 2, 2024
1 parent 28064d4 commit 5e83aed
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import org.sopt.dosopttemplate.data.dto.remote.request.RequestLoginDto
import org.sopt.dosopttemplate.data.dto.remote.respose.ResponseLoginDto
import org.sopt.dosopttemplate.data.repositoryimpl.AuthRepository
import org.sopt.dosopttemplate.ui.model.UserInfo
import org.sopt.dosopttemplate.utils.UiState

class AuthViewModel(private val authRepository: AuthRepository) : ViewModel() {
private val _loginState = MutableStateFlow<LoginState>(LoginState.Loading)
val loginState: StateFlow<LoginState> = _loginState.asStateFlow()
private val _loginState = MutableStateFlow<UiState<ResponseLoginDto>>(UiState.Loading)
val loginState: StateFlow<UiState<ResponseLoginDto>> get() = _loginState.asStateFlow()

private val _isLoginButtonClicked: MutableLiveData<Boolean> = MutableLiveData(false)
val isLoginButtonClicked: LiveData<Boolean>
Expand All @@ -28,15 +30,15 @@ class AuthViewModel(private val authRepository: AuthRepository) : ViewModel() {
if (it.isSuccessful) {
val response = it.body()
if (response != null) {
_loginState.value = LoginState.Success(response)
_loginState.value = UiState.Success(response)
Log.d("server", _loginState.value.toString())
UserInfo.updateUserInfo(
id = response.id.toString(),
nickName = response.nickname.toString(),
)
}
} else {
_loginState.value = LoginState.Error
_loginState.value = UiState.Error
Log.d("server", it.code().toString())
}
}.onFailure {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class SignUpActivity : AppCompatActivity() {
}

is UiState.Error -> toast(getString(R.string.toast_signUp_fail))
is UiState.Loading -> toast("회원가입 중")
is UiState.Loading -> {}
}
}
}
Expand Down

This file was deleted.

0 comments on commit 5e83aed

Please sign in to comment.