Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

🔗 :: (#177) 텍스트 필드 커서 밀림 버그 해결 #217

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal fun ComparePasswordScreen(
val context = LocalContext.current
val focusManager = LocalFocusManager.current
val state by resetPasswordViewModel.collectAsState()
val currentPassword = resetPasswordViewModel.currentPassword

resetPasswordViewModel.collectSideEffect {
when (it) {
Expand All @@ -58,7 +59,7 @@ internal fun ComparePasswordScreen(

val onPasswordChanged = { password: String ->
resetPasswordViewModel.setCurrentPassword(password)
if (state.currentPassword.length != password.length) {
if (currentPassword.length != password.length) {
resetPasswordViewModel.setComparePasswordErrorState(
comparePasswordErrorState = false,
)
Expand All @@ -85,7 +86,7 @@ internal fun ComparePasswordScreen(
}
Spacer(modifier = Modifier.height(28.dp))
JobisBoxTextField(
value = state.currentPassword,
value = currentPassword,
onValueChanged = onPasswordChanged,
hint = stringResource(id = R.string.hint_original_password),
textFieldType = TextFieldType.PASSWORD,
Expand All @@ -96,7 +97,7 @@ internal fun ComparePasswordScreen(
Spacer(modifier = Modifier.weight(1f))
JobisLargeButton(
text = stringResource(id = R.string.complete),
enabled = state.currentPassword.isNotEmpty() && !state.comparePasswordErrorState,
enabled = currentPassword.isNotEmpty() && !state.comparePasswordErrorState,
onClick = resetPasswordViewModel::comparePassword,
)
Spacer(modifier = Modifier.height(32.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ internal fun ResetPasswordScreen(
val context = LocalContext.current
val state by resetPasswordViewModel.collectAsState()
val focusManager = LocalFocusManager.current
val newPassword = state.newPassword
val passwordRepeat = state.passwordRepeat
val newPassword = resetPasswordViewModel.newPassword
val passwordRepeat = resetPasswordViewModel.passwordRepeat
val onClick: () -> Unit = {
when (getPreviousDestination().toString()) {
AuthDestinations.ResetPasswordVerifyEmail -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ internal fun ResetPasswordVerifyEmailScreen(
val context = LocalContext.current
val state by resetPasswordViewModel.collectAsState()
val focusManager = LocalFocusManager.current
val email = state.email
val authCode = state.authCode
val email = resetPasswordViewModel.email
val authCode = resetPasswordViewModel.authCode
val sendAuthCodeState = state.sendAuthCodeState

resetPasswordViewModel.collectSideEffect {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package team.retum.jobis_android.feature.auth.resetpassword

import androidx.annotation.StringRes
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -40,11 +43,22 @@ internal class ResetPasswordViewModel @Inject constructor(
initialState = ResetPasswordState(),
)

var email by mutableStateOf("")
private set
var currentPassword by mutableStateOf("")
private set
var authCode by mutableStateOf("")
private set
var newPassword by mutableStateOf("")
private set
var passwordRepeat by mutableStateOf("")
private set

internal fun sendVerificationCode() = intent {
viewModelScope.launch(Dispatchers.IO) {
sendVerificationCodeUseCase(
sendVerificationCodeParam = SendVerificationCodeParam(
email = state.email,
email = email,
authCodeType = AuthCodeType.PASSWORD,
),
).onSuccess {
Expand All @@ -69,8 +83,8 @@ internal class ResetPasswordViewModel @Inject constructor(
viewModelScope.launch(Dispatchers.IO) {
verifyEmailUseCase(
verifyEmailParam = VerifyEmailParam(
email = state.email,
authCode = state.authCode,
email = email,
authCode = authCode,
),
).onSuccess {
postSideEffect(sideEffect = ResetPasswordSideEffect.SuccessVerification)
Expand All @@ -91,7 +105,7 @@ internal class ResetPasswordViewModel @Inject constructor(
internal fun comparePassword() = intent {
viewModelScope.launch(Dispatchers.IO) {
comparePasswordUseCase(
password = state.currentPassword,
password = currentPassword,
).onSuccess {
postSideEffect(sideEffect = ResetPasswordSideEffect.SuccessVerification)
}.onFailure {
Expand All @@ -117,8 +131,8 @@ internal class ResetPasswordViewModel @Inject constructor(
viewModelScope.launch(Dispatchers.IO) {
changePasswordUseCase(
changePasswordParam = ChangePasswordParam(
currentPassword = state.currentPassword,
newPassword = state.newPassword,
currentPassword = currentPassword,
newPassword = newPassword,
),
).onSuccess {
postSideEffect(sideEffect = ResetPasswordSideEffect.SuccessChangePassword)
Expand All @@ -132,8 +146,8 @@ internal class ResetPasswordViewModel @Inject constructor(
viewModelScope.launch(Dispatchers.IO) {
resetPasswordUseCase(
resetPasswordParam = ResetPasswordParam(
email = state.email,
password = state.newPassword,
email = email,
password = newPassword,
),
).onSuccess {
postSideEffect(ResetPasswordSideEffect.SuccessResetPassword)
Expand All @@ -143,64 +157,48 @@ internal class ResetPasswordViewModel @Inject constructor(
}
}

internal fun setEmail(
email: String,
) = intent {
reduce {
setEmailErrorState(emailErrorState = false)
state.copy(email = email)
}
internal fun setEmail(email: String) {
this.email = email
setEmailErrorState(emailErrorState = false)
}

internal fun setAuthCode(
authCode: String,
) = intent {
internal fun setAuthCode(authCode: String) {
authCode.take(6)
this.authCode = authCode
if (authCode.length == 6) {
postSideEffect(ResetPasswordSideEffect.ClearFocus)
}
reduce {
state.copy(authCode = authCode)
intent {
postSideEffect(ResetPasswordSideEffect.ClearFocus)
}
}
}

internal fun setCurrentPassword(
currentPassword: String,
) = intent {
reduce {
state.copy(
currentPassword = currentPassword,
)
}
internal fun setCurrentPassword(currentPassword: String) {
this.currentPassword = currentPassword
}

internal fun setNewPassword(
newPassword: String,
) = intent {
reduce {
with(state) {
copy(
newPassword = newPassword,
passwordFormatErrorState = !Regex(Regex.PASSWORD).matches(newPassword),
passwordRepeatErrorState = newPassword != passwordRepeat && passwordRepeat.isNotBlank(),
)
internal fun setNewPassword(newPassword: String) {
this.newPassword = newPassword
intent {
reduce {
with(state) {
copy(
passwordFormatErrorState = !Regex(Regex.PASSWORD).matches(newPassword),
passwordRepeatErrorState = newPassword != passwordRepeat && passwordRepeat.isNotBlank(),
)
}
}
setButtonEnabled()
}
setButtonEnabled()
}

internal fun setPasswordRepeat(
passwordRepeat: String,
) = intent {
reduce {
with(state) {
copy(
passwordRepeat = passwordRepeat,
passwordRepeatErrorState = newPassword != passwordRepeat,
)
internal fun setPasswordRepeat(passwordRepeat: String) {
this.passwordRepeat = passwordRepeat
intent {
reduce {
state.copy(passwordRepeatErrorState = newPassword != passwordRepeat)
}
setButtonEnabled()
}
setButtonEnabled()
}

private fun setButtonEnabled() = intent {
Expand Down Expand Up @@ -251,11 +249,6 @@ internal class ResetPasswordViewModel @Inject constructor(
}

data class ResetPasswordState(
val email: String = "",
val authCode: String = "",
val currentPassword: String = "",
val newPassword: String = "",
val passwordRepeat: String = "",
val emailErrorState: Boolean = false,
val authCodeErrorState: Boolean = false,
val sendAuthCodeState: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ internal fun SignInScreen(
}
Spacer(modifier = Modifier.height(80.dp))
SignInInputs(
email = state.email,
password = state.password,
email = signInScreenViewModel.email,
password = signInScreenViewModel.password,
onEmailChanged = signInScreenViewModel::setEmail,
onPasswordChanged = signInScreenViewModel::setPassword,
emailError = state.emailError,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package team.retum.jobis_android.feature.auth.signin

import androidx.annotation.StringRes
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
Expand All @@ -25,12 +28,17 @@ class SignInScreenViewModel @Inject constructor(

override val container = container<SignInState, SignInSideEffect>(SignInState())

var email by mutableStateOf("")
private set
var password by mutableStateOf("")
private set

internal fun postLogin() = intent {
viewModelScope.launch {
signInUseCase(
param = SignInParam(
accountId = state.email,
password = state.password,
accountId = email,
password = password,
isAutoLogin = state.autoSignIn,
),
).onSuccess {
Expand Down Expand Up @@ -69,23 +77,23 @@ class SignInScreenViewModel @Inject constructor(
}
}

internal fun setEmail(email: String) = intent {
internal fun setEmail(email: String) {
this.email = email
setSignInButtonEnabled()
reduce {
state.copy(
email = email,
emailError = false,
)
intent {
reduce {
state.copy(emailError = false)
}
}
}

internal fun setPassword(password: String) = intent {
internal fun setPassword(password: String) {
this.password = password
setSignInButtonEnabled()
reduce {
state.copy(
password = password,
passwordError = false,
)
intent {
reduce {
state.copy(passwordError = false)
}
}
}

Expand All @@ -105,8 +113,6 @@ class SignInScreenViewModel @Inject constructor(
}

data class SignInState(
val email: String = "",
val password: String = "",
val autoSignIn: Boolean = false,
val emailError: Boolean = false,
val passwordError: Boolean = false,
Expand Down
Loading
Loading