Skip to content

Commit

Permalink
[FEAT/#206] 수정 정보 유효성 검사 로직
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeyubin committed Sep 1, 2024
1 parent 0906e9c commit 23bf23b
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import com.terning.feature.mypage.mypage.component.MyPageItem
fun MyPageRoute(
paddingValues: PaddingValues,
viewModel: MyPageViewModel = hiltViewModel(),
navigateToProfileEdit: (String) -> Unit
navigateToProfileEdit: (String, Int) -> Unit
) {
val state by viewModel.state.collectAsStateWithLifecycle()
val context = LocalContext.current
Expand All @@ -67,7 +67,10 @@ fun MyPageRoute(
viewModel.sideEffects.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle)
.collect { sideEffect ->
when (sideEffect) {
is MyPageSideEffect.NavigateToProfileEdit -> navigateToProfileEdit(state.name)
is MyPageSideEffect.NavigateToProfileEdit -> navigateToProfileEdit(
state.name,
state.profile
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fun NavGraphBuilder.myPageNavGraph(
composable<MyPage>{
MyPageRoute(
paddingValues = paddingValues,
navigateToProfileEdit = { name -> navHostController.navigateProfileEdit(name) }
navigateToProfileEdit = { name, profile -> navHostController.navigateProfileEdit(name, profile) }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ fun ProfileEditRoute(
navigateUp: () -> Unit,
viewModel: ProfileEditViewModel = hiltViewModel(),
initialName: String,
initialProfile: Int
) {
val state by viewModel.state.collectAsStateWithLifecycle()

Expand All @@ -56,17 +57,18 @@ fun ProfileEditRoute(
}

LaunchedEffect(key1 = true) {
viewModel.updateName(initialName)
viewModel.updateInitialInfo(initialName = initialName, initialProfile = initialProfile)
}

if (state.showBottomSheet) {
ProfileBottomSheet(
onDismiss = { viewModel.updateBottomSheet(false) },
onSaveClick = { index ->
viewModel.updateBottomSheet(false)
viewModel.updateCharacter(index)
viewModel.updateProfile(index)
viewModel.checkIsInfoChange(editName = state.name, editProfile = index)
},
initialSelectedOption = state.character
initialSelectedOption = state.profile
)
}

Expand All @@ -86,12 +88,13 @@ fun ProfileEditRoute(
},
onInputChange = { editName ->
viewModel.updateName(editName)
viewModel.checkIsInfoChange(editName = editName, editProfile = state.profile)
},
onSaveClick = { viewModel.navigateUp() },
name = state.name,
onBackButtonClick = { viewModel.navigateUp() },
onValidationChanged = { isValid ->
viewModel.updateButtonValidation(isValid)
if (state.isInfoChange) viewModel.updateButtonValidation(isValid)
}
)
}
Expand Down Expand Up @@ -123,8 +126,7 @@ fun ProfileEditScreen(
)
Spacer(modifier = modifier.height(24.dp))
Column(
modifier = modifier
.padding(horizontal = 24.dp)
modifier = modifier.padding(horizontal = 24.dp)
) {
Text(
text = stringResource(id = R.string.sign_up_profile_image),
Expand All @@ -133,12 +135,12 @@ fun ProfileEditScreen(
)
Spacer(modifier = modifier.height(20.dp))
ProfileWithPlusButton(
modifier = modifier
modifier = Modifier
.noRippleClickable {
onProfileEditClick(true)
}
.align(Alignment.CenterHorizontally),
index = profileEditState.character
index = profileEditState.profile
)
Spacer(modifier = modifier.height(48.dp))
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package com.terning.feature.mypage.profileedit

data class ProfileEditState(
val name: String = "",
val character: Int = 0,
val initialName: String = "",
val profile: Int = 0,
val initialProfile: Int = 0,
val isInfoChange: Boolean = false,
val isButtonValid: Boolean = false,
val authType: String = "",
val showBottomSheet: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ class ProfileEditViewModel @Inject constructor() : ViewModel() {
_state.value = _state.value.copy(isButtonValid = isValid)
}

fun updateCharacter(character: Int) {
_state.value = _state.value.copy(character = character)
}

fun navigateUp() = viewModelScope.launch { _sideEffects.emit(ProfileEditSideEffect.NavigateUp) }

fun updateBottomSheet(isVisible: Boolean) {
Expand All @@ -39,7 +35,26 @@ class ProfileEditViewModel @Inject constructor() : ViewModel() {
_state.value = _state.value.copy(name = name)
}

companion object {
private const val KAKA0 = "KAKAO"
fun updateProfile(profile: Int) {
_state.value = _state.value.copy(profile = profile)
}

fun updateInitialInfo(initialName: String, initialProfile: Int) {
_state.value = _state.value.copy(
name = initialName,
initialName = initialName,
profile = initialProfile,
initialProfile = initialProfile
)
}

fun checkIsInfoChange(editName: String, editProfile: Int) {
_state.value = _state.value.copy(
isInfoChange = when {
editName == _state.value.initialName && editProfile == _state.value.initialProfile -> false
else -> true
}
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.tween
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.foundation.layout.PaddingValues
import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
Expand All @@ -17,10 +16,11 @@ import kotlinx.serialization.Serializable

fun NavController.navigateProfileEdit(
name: String,
profile: Int,
navOptions: NavOptions? = null
) {
navigate(
route = ProfileEdit(name = name),
route = ProfileEdit(name = name, profile = profile),
navOptions = navOptions
)
}
Expand All @@ -45,12 +45,14 @@ fun NavGraphBuilder.profileEditNavGraph(
val args = it.toRoute<ProfileEdit>()
ProfileEditRoute(
initialName = args.name,
initialProfile = args.profile,
navigateUp = { navHostController.navigateUp() }
)
}
}

@Serializable
data class ProfileEdit(
val name: String
val name: String,
val profile: Int
) : Route

0 comments on commit 23bf23b

Please sign in to comment.