flattening loading state to the handle entry points, reducing duplication
This commit is contained in:
parent
5001be9f21
commit
ee693b5ad4
|
@ -257,15 +257,15 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
private fun handleRegisterAction(action: RegisterAction, onNextRegistrationStepAction: (FlowResult) -> Unit) {
|
private fun handleRegisterAction(action: RegisterAction, onNextRegistrationStepAction: (FlowResult) -> Unit) {
|
||||||
currentJob = viewModelScope.launch {
|
currentJob = viewModelScope.launch {
|
||||||
|
if (action.hasLoadingState()) {
|
||||||
|
setState { copy(isLoading = true) }
|
||||||
|
}
|
||||||
internalRegisterAction(action, onNextRegistrationStepAction)
|
internalRegisterAction(action, onNextRegistrationStepAction)
|
||||||
|
setState { copy(isLoading = false) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun internalRegisterAction(action: RegisterAction, onNextRegistrationStepAction: (FlowResult) -> Unit) {
|
private suspend fun internalRegisterAction(action: RegisterAction, onNextRegistrationStepAction: (FlowResult) -> Unit) {
|
||||||
if (action.hasLoadingState()) {
|
|
||||||
setState { copy(isLoading = true) }
|
|
||||||
}
|
|
||||||
|
|
||||||
runCatching { registrationActionHandler.handleRegisterAction(registrationWizard, action) }
|
runCatching { registrationActionHandler.handleRegisterAction(registrationWizard, action) }
|
||||||
.fold(
|
.fold(
|
||||||
onSuccess = {
|
onSuccess = {
|
||||||
|
@ -285,7 +285,6 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
setState { copy(isLoading = false) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun emitFlowResultViewEvent(flowResult: FlowResult) {
|
private fun emitFlowResultViewEvent(flowResult: FlowResult) {
|
||||||
|
@ -293,17 +292,15 @@ class OnboardingViewModel @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleRegisterWith(action: OnboardingAction.Register) {
|
private fun handleRegisterWith(action: OnboardingAction.Register) {
|
||||||
currentJob = viewModelScope.launch {
|
reAuthHelper.data = action.password
|
||||||
reAuthHelper.data = action.password
|
handleRegisterAction(
|
||||||
internalRegisterAction(
|
RegisterAction.CreateAccount(
|
||||||
RegisterAction.CreateAccount(
|
action.username,
|
||||||
action.username,
|
action.password,
|
||||||
action.password,
|
action.initialDeviceName
|
||||||
action.initialDeviceName
|
),
|
||||||
),
|
::emitFlowResultViewEvent
|
||||||
::emitFlowResultViewEvent
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleResetAction(action: OnboardingAction.ResetAction) {
|
private fun handleResetAction(action: OnboardingAction.ResetAction) {
|
||||||
|
|
Loading…
Reference in New Issue