Skip to content

Instantly share code, notes, and snippets.

@Daniel-sims
Last active October 16, 2022 17:19
Show Gist options
  • Save Daniel-sims/2d361a5bc123f0e437355b55fbdd244a to your computer and use it in GitHub Desktop.
Save Daniel-sims/2d361a5bc123f0e437355b55fbdd244a to your computer and use it in GitHub Desktop.
Updating UI State with LoginSuccessful navigation event
private fun attemptLogin() {
viewModelScope.launch {
if (listOf(validateEmail(), validatePassword()).allValid()) {
uiState = uiState.copy(loading = true)
authenticationRepository.login(
email = uiState.content.email,
password = uiState.content.password
).handleResult(
onError = { loginError ->
uiState = uiState.copy(
loading = false,
error = uiState.error.copy(loginError = loginError)
)
},
onSuccess = {
uiState = uiState.copy(
navigationEvent = UiState.NavigationEvents.LoginSuccessful
)
}
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment