diff --git a/feature/survey/src/main/java/com/wap/wapp/feature/survey/SurveyViewModel.kt b/feature/survey/src/main/java/com/wap/wapp/feature/survey/SurveyViewModel.kt index a6453d5e..9b63087a 100644 --- a/feature/survey/src/main/java/com/wap/wapp/feature/survey/SurveyViewModel.kt +++ b/feature/survey/src/main/java/com/wap/wapp/feature/survey/SurveyViewModel.kt @@ -36,48 +36,42 @@ class SurveyViewModel @Inject constructor( getUserRole() } - private fun getUserRole() { - viewModelScope.launch { - getUserRoleUseCase() - .onSuccess { userRole -> - _userRoleUiState.value = UserRoleUiState.Success(userRole) - } - .onFailure { throwable -> - _surveyEvent.emit(SurveyUiEvent.Failure(throwable)) - } - } + private fun getUserRole() = viewModelScope.launch { + getUserRoleUseCase() + .onSuccess { userRole -> + _userRoleUiState.value = UserRoleUiState.Success(userRole) + } + .onFailure { throwable -> + _surveyEvent.emit(SurveyUiEvent.Failure(throwable)) + } } - fun getSurveyFormList() { - viewModelScope.launch { - getSurveyFormListUseCase() - .onSuccess { surveyFormList -> - val filteredSurveyFormList = surveyFormList.filter { survey -> - survey.isBeforeDeadline() - } - _surveyFormListUiState.value = - SurveyFormListUiState.Success(filteredSurveyFormList) + fun getSurveyFormList() = viewModelScope.launch { + getSurveyFormListUseCase() + .onSuccess { surveyFormList -> + val filteredSurveyFormList = surveyFormList.filter { survey -> + survey.isBeforeDeadline() } - .onFailure { throwable -> - _surveyEvent.emit(SurveyUiEvent.Failure(throwable)) - } - } + _surveyFormListUiState.value = + SurveyFormListUiState.Success(filteredSurveyFormList) + } + .onFailure { throwable -> + _surveyEvent.emit(SurveyUiEvent.Failure(throwable)) + } } - fun isSubmittedSurvey(surveyFormId: String) { - viewModelScope.launch { - isSubmittedSurveyUseCase(surveyFormId) - .onSuccess { isSubmittedSurvey -> - if (isSubmittedSurvey) { - _surveyEvent.emit(SurveyUiEvent.AlreadySubmitted) - } else { - _surveyEvent.emit(SurveyUiEvent.NotSubmitted(surveyFormId)) - } - } - .onFailure { throwable -> - _surveyEvent.emit(SurveyUiEvent.Failure(throwable)) + fun isSubmittedSurvey(surveyFormId: String) = viewModelScope.launch { + isSubmittedSurveyUseCase(surveyFormId) + .onSuccess { isSubmittedSurvey -> + if (isSubmittedSurvey) { + _surveyEvent.emit(SurveyUiEvent.AlreadySubmitted) + } else { + _surveyEvent.emit(SurveyUiEvent.NotSubmitted(surveyFormId)) } - } + } + .onFailure { throwable -> + _surveyEvent.emit(SurveyUiEvent.Failure(throwable)) + } } sealed class UserRoleUiState { @@ -87,6 +81,7 @@ class SurveyViewModel @Inject constructor( sealed class SurveyFormListUiState { data object Init : SurveyFormListUiState() + data object Loading : SurveyFormListUiState() data class Success(val surveyFormList: List) : SurveyFormListUiState() }