Skip to content

Commit

Permalink
reusing error component in login screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ouchadam committed Oct 9, 2022
1 parent ec5c58a commit 94731d0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 37 deletions.
1 change: 1 addition & 0 deletions features/login/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ dependencies {
implementation project(":matrix:services:auth")
implementation project(":matrix:services:profile")
implementation project(":matrix:services:crypto")
implementation project(":design-library")
implementation project(":core")
}
41 changes: 4 additions & 37 deletions features/login/src/main/kotlin/app/dapk/st/login/LoginScreen.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app.dapk.st.login

import android.widget.Toast
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
Expand Down Expand Up @@ -32,6 +31,8 @@ import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
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.LoginScreenState.*

Expand All @@ -49,42 +50,8 @@ fun LoginScreen(loginViewModel: LoginViewModel, onLoggedIn: () -> Unit) {
val keyboardController = LocalSoftwareKeyboardController.current

when (val state = loginViewModel.state) {
is Error -> {
val openDetailsDialog = remember { mutableStateOf(false) }

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 Error -> GenericError(cause = state.cause, action = { loginViewModel.start() })
Loading -> CenteredLoading()

is Content ->
Row {
Expand Down

0 comments on commit 94731d0

Please sign in to comment.