Skip to content

Commit

Permalink
#39 [REFACTOR] 사용자 정보 저장 로직 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
youjin09222 committed Jan 23, 2025
1 parent f1ce4de commit 8e070a6
Showing 1 changed file with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,19 @@ class EditProfileViewModel @Inject constructor(
}

fun navigateToMyPage() {
saveNickname(_userInfoState.value.nickname)
saveProfileImage(_userInfoState.value.profileImage)
executeInScope {
saveUserInfo()
withContext(Dispatchers.Main) {
emitSideEffect(EditProfileSideEffect.NavigateToMyPage)
}
}
}

private suspend fun saveUserInfo() {
userInfoRepository.saveNickname(_userInfoState.value.nickname)
_userInfoState.value.profileImage?.let { userInfoRepository.saveProfileImage(it) }
}

fun onNicknameChanged(nickname: String) {
_userInfoState.update { it.copy(nickname = nickname) }
validateChanges()
Expand All @@ -66,18 +70,6 @@ class EditProfileViewModel @Inject constructor(
return !nickname.isNullOrBlank() && nickname.length in 1..10 && nickname.all { it.isLetterOrDigit() }
}

private fun saveNickname(nickname: String) {
executeInScope {
userInfoRepository.saveNickname(nickname)
}
}

private fun saveProfileImage(imageUri: String?) {
executeInScope {
imageUri?.let { userInfoRepository.saveProfileImage(it) }
}
}

fun updateGalleryPermissionState(isGranted: Boolean) {
_editProfileState.update { it.copy(isPermissionGranted = isGranted) }
}
Expand All @@ -91,10 +83,8 @@ class EditProfileViewModel @Inject constructor(
}

fun updateProfileImage(imageUri: String?) {
executeInScope {
_userInfoState.update { it.copy(profileImage = imageUri) }
validateChanges()
}
_userInfoState.update { it.copy(profileImage = imageUri) }
validateChanges()
}

private fun executeInScope(block: suspend () -> Unit) {
Expand Down

0 comments on commit 8e070a6

Please sign in to comment.