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 and BGuga committed Oct 17, 2023
1 parent 26b2f4a commit 691a187
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 691a187

Please sign in to comment.