diff --git a/design-library/src/main/kotlin/app/dapk/st/design/components/Error.kt b/design-library/src/main/kotlin/app/dapk/st/design/components/Error.kt index 722ff2c..20db56c 100644 --- a/design-library/src/main/kotlin/app/dapk/st/design/components/Error.kt +++ b/design-library/src/main/kotlin/app/dapk/st/design/components/Error.kt @@ -1,21 +1,44 @@ package app.dapk.st.design.components -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.* +import androidx.compose.material3.AlertDialog import androidx.compose.material3.Button import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp @Composable -fun GenericError(retryAction: () -> Unit) { - Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { +fun GenericError(message: String = "Something went wrong...", label: String = "Retry", moreDetails: String? = null, action: () -> Unit) { + 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(moreDetails!!) + } + ) + } + Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) { Column(horizontalAlignment = Alignment.CenterHorizontally) { - Text("Something went wrong...") - Button(onClick = { retryAction() }) { - Text("Retry") + Text(message) + if (moreDetails != null) { + 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 = { action() }) { + Text(label.uppercase()) } } }