@@ -18,6 +18,7 @@ import `in`.koreatech.koin.domain.util.onSuccess
18
18
import `in`.koreatech.koin.ui.userinfo.state.NicknameCheckState
19
19
import `in`.koreatech.koin.ui.userinfo.state.NicknameState
20
20
import kotlinx.coroutines.flow.SharingStarted
21
+ import kotlinx.coroutines.flow.StateFlow
21
22
import kotlinx.coroutines.flow.combine
22
23
import kotlinx.coroutines.flow.filter
23
24
import kotlinx.coroutines.flow.flow
@@ -36,12 +37,6 @@ class UserInfoEditViewModel @Inject constructor(
36
37
private val _user = MutableLiveData <User >()
37
38
val user: LiveData <User > get() = _user
38
39
39
- val depts = flow { emit(getDeptNamesUseCase()) }
40
- .combine(user.asFlow()) { depts, user -> depts to user }
41
- .filter{ it.second.isStudent }
42
- .map { it.first to (it.second as User .Student ).major }
43
- .stateIn(viewModelScope, SharingStarted .WhileSubscribed (5000 ), listOf<String >() to null )
44
-
45
40
private val _getDeptErrorMessage = MutableLiveData <String >()
46
41
val getDeptErrorMessage: LiveData <String > get() = _getDeptErrorMessage
47
42
@@ -57,6 +52,12 @@ class UserInfoEditViewModel @Inject constructor(
57
52
private val _userInfoEditedEvent = SingleLiveEvent <Unit >()
58
53
val userInfoEditedEvent: LiveData <Unit > get() = _userInfoEditedEvent
59
54
55
+ val depts: StateFlow <Pair <List <String >, String? >> = flow { emit(getDeptNamesUseCase()) }
56
+ .combine(user.asFlow()) { depts, user -> depts to user }
57
+ .filter { it.second.isStudent }
58
+ .map { it.first to (it.second as User .Student ).major }
59
+ .stateIn(viewModelScope, SharingStarted .WhileSubscribed (5000 ), listOf<String >() to null )
60
+
60
61
fun getUserInfo () = viewModelScope.launchWithLoading {
61
62
getUserInfoUseCase()
62
63
.onSuccess { user ->
@@ -101,7 +102,8 @@ class UserInfoEditViewModel @Inject constructor(
101
102
nickname : String ,
102
103
separatedPhoneNumber : List <String >? ,
103
104
gender : Gender ? ,
104
- studentId : String
105
+ studentId : String ,
106
+ major : String
105
107
) {
106
108
if (isLoading.value == false ) {
107
109
viewModelScope.launchWithLoading {
@@ -113,6 +115,7 @@ class UserInfoEditViewModel @Inject constructor(
113
115
separatedPhoneNumber = separatedPhoneNumber,
114
116
gender = gender,
115
117
studentId = studentId,
118
+ major = major,
116
119
checkedEmailValidation = nicknameState.value?.let {
117
120
it.nickname == nickname && it.isNicknameDuplicated == false
118
121
} ? : false
0 commit comments