Skip to content

Commit

Permalink
[AN/USER] refactor: 학교 선택 화면 success 캐스팅 코드 리팩(#473) #475
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilyCh0 authored Oct 4, 2023
1 parent 5524215 commit bc6ad2c
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class SelectSchoolViewModel @Inject constructor(
viewModelScope.launch {
schoolRepository.loadSchools()
.onSuccess { schools ->
if (uiState.value is SelectSchoolUiState.Success) {
val successState = (uiState.value as SelectSchoolUiState.Success)
_uiState.value = successState.copy(schools = schools)
val state = uiState.value
if (state is SelectSchoolUiState.Success) {
_uiState.value = state.copy(schools = schools)
} else {
_uiState.value = SelectSchoolUiState.Success(schools)
}
Expand All @@ -46,20 +46,18 @@ class SelectSchoolViewModel @Inject constructor(
}

fun selectSchool(schoolId: Long) {
if (uiState.value is SelectSchoolUiState.Success) {
_uiState.value =
(uiState.value as SelectSchoolUiState.Success).copy(selectedSchoolId = schoolId)
val state = uiState.value
if (state is SelectSchoolUiState.Success) {
_uiState.value = state.copy(selectedSchoolId = schoolId)
}
}

fun showStudentVerification() {
viewModelScope.launch {
if (uiState.value is SelectSchoolUiState.Success) {
val success = uiState.value as SelectSchoolUiState.Success
success.selectedSchoolId?.let { schoolId ->
_event.emit(
SelectSchoolEvent.ShowStudentVerification(schoolId)
)
val state = uiState.value
if (state is SelectSchoolUiState.Success) {
state.selectedSchoolId?.let { schoolId ->
_event.emit(SelectSchoolEvent.ShowStudentVerification(schoolId))
}
}
}
Expand Down

0 comments on commit bc6ad2c

Please sign in to comment.