Minor cleanup of LoginWithDeviceViewModel (#881)

This commit is contained in:
David Perez 2024-01-30 17:52:24 -06:00 committed by Álison Fernandes
parent c88b01ea11
commit 2be47c5b0f

View file

@ -50,16 +50,7 @@ class LoginWithDeviceViewModel @Inject constructor(
} }
private fun handleErrorDialogDismissed() { private fun handleErrorDialogDismissed() {
val viewState = mutableStateFlow.value.viewState as? LoginWithDeviceState.ViewState.Content updateContent { it.copy(shouldShowErrorDialog = false) }
if (viewState != null) {
mutableStateFlow.update {
it.copy(
viewState = viewState.copy(
shouldShowErrorDialog = false,
),
)
}
}
} }
private fun handleResendNotificationClicked() { private fun handleResendNotificationClicked() {
@ -87,7 +78,6 @@ class LoginWithDeviceViewModel @Inject constructor(
} }
is AuthRequestResult.Error -> { is AuthRequestResult.Error -> {
mutableStateFlow.update { mutableStateFlow.update {
it.copy( it.copy(
viewState = LoginWithDeviceState.ViewState.Content( viewState = LoginWithDeviceState.ViewState.Content(
@ -115,18 +105,19 @@ class LoginWithDeviceViewModel @Inject constructor(
} }
private fun setIsResendNotificationLoading(isLoading: Boolean) { private fun setIsResendNotificationLoading(isLoading: Boolean) {
when (val viewState = mutableStateFlow.value.viewState) { updateContent { it.copy(isResendNotificationLoading = isLoading) }
is LoginWithDeviceState.ViewState.Content -> { }
mutableStateFlow.update {
it.copy( private inline fun updateContent(
viewState = viewState.copy( crossinline block: (
isResendNotificationLoading = isLoading, LoginWithDeviceState.ViewState.Content,
), ) -> LoginWithDeviceState.ViewState.Content?,
) ) {
} val currentViewState = state.viewState
} val updatedContent = (currentViewState as? LoginWithDeviceState.ViewState.Content)
else -> Unit ?.let(block)
} ?: return
mutableStateFlow.update { it.copy(viewState = updatedContent) }
} }
} }