reusing error component in login screen

This commit is contained in:
Adam Brown 2022-10-09 15:55:10 +01:00
parent ec5c58a95c
commit 94731d006e
2 changed files with 5 additions and 37 deletions

View File

@ -7,5 +7,6 @@ dependencies {
implementation project(":matrix:services:auth") implementation project(":matrix:services:auth")
implementation project(":matrix:services:profile") implementation project(":matrix:services:profile")
implementation project(":matrix:services:crypto") implementation project(":matrix:services:crypto")
implementation project(":design-library")
implementation project(":core") implementation project(":core")
} }

View File

@ -1,7 +1,6 @@
package app.dapk.st.login package app.dapk.st.login
import android.widget.Toast import android.widget.Toast
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
@ -32,6 +31,8 @@ import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import app.dapk.st.core.StartObserving import app.dapk.st.core.StartObserving
import app.dapk.st.core.components.CenteredLoading
import app.dapk.st.design.components.GenericError
import app.dapk.st.login.LoginEvent.LoginComplete import app.dapk.st.login.LoginEvent.LoginComplete
import app.dapk.st.login.LoginScreenState.* import app.dapk.st.login.LoginScreenState.*
@ -49,42 +50,8 @@ fun LoginScreen(loginViewModel: LoginViewModel, onLoggedIn: () -> Unit) {
val keyboardController = LocalSoftwareKeyboardController.current val keyboardController = LocalSoftwareKeyboardController.current
when (val state = loginViewModel.state) { when (val state = loginViewModel.state) {
is Error -> { is Error -> GenericError(cause = state.cause, action = { loginViewModel.start() })
val openDetailsDialog = remember { mutableStateOf(false) } Loading -> CenteredLoading()
if (openDetailsDialog.value) {
AlertDialog(
onDismissRequest = { openDetailsDialog.value = false },
confirmButton = {
Button(onClick = { openDetailsDialog.value = false }) {
Text("OK")
}
},
title = { Text("Details") },
text = {
Text(state.cause.message ?: "Unknown")
}
)
}
Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text("Something went wrong")
Text("Tap for more details".uppercase(), fontSize = 12.sp, modifier = Modifier.clickable { openDetailsDialog.value = true }.padding(12.dp))
Spacer(modifier = Modifier.height(12.dp))
Button(onClick = {
loginViewModel.start()
}) {
Text("Retry".uppercase())
}
}
}
}
Loading -> {
Box(contentAlignment = Alignment.Center) {
CircularProgressIndicator()
}
}
is Content -> is Content ->
Row { Row {