Use buttonComponent on Form.kt

main
CAPEL Maxime 2023-12-21 15:39:53 +01:00
parent 2fa3ce4714
commit 1d031fe96c
2 changed files with 20 additions and 48 deletions

View File

@ -21,6 +21,7 @@ import androidx.compose.ui.input.key.*
import androidx.compose.ui.unit.dp
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import main.component.buttonComponent
import java.io.File
import java.io.IOException
@ -55,20 +56,14 @@ fun formPage(glossary: Glossary, onCancelClick: () -> Unit) {
Text("Le mot '${name.value}' a bien été ajouté au glossaire.")
},
confirmButton = {
Button(
buttonComponent(
onClick = {
openDialog.value = false
resetFields(name, description, mainContext, secondaryContext, relatedTo, synonymous, antonym)
},
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
width = 100,
text = "Fermer"
)
) {
Text("Fermer")
}
}
)
}
@ -324,23 +319,14 @@ fun formPage(glossary: Glossary, onCancelClick: () -> Unit) {
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly
) {
Button(
onClick = onCancelClick,
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
)
) {
Icon(imageVector = Icons.Default.ArrowBack, contentDescription = null)
Text("Retour")
}
Button(
buttonComponent(onClick = onCancelClick, width = 150, text = "Retour", icon = Icons.Default.ArrowBack)
buttonComponent(
onClick = {
// Validate the fields
if (name.value.isBlank() || mainContext.value.isBlank()) {
// Show the snackbar when validation fails
requiredFieldsSnackbarVisibleState.value = true
return@Button
return@buttonComponent
}
val wordsList = loadDatasFromFile(glossary.jsonFilePath).toMutableList()
@ -352,7 +338,7 @@ fun formPage(glossary: Glossary, onCancelClick: () -> Unit) {
if (wordsList.any { it.name.equals(name.value, ignoreCase = true) }) {
println("Le mot '${name.value}' existe déjà dans le glossaire. Ajout annulé.")
alreadyExistSnackbarVisibleState.value = true
return@Button
return@buttonComponent
}
val newWord = Word(
@ -369,14 +355,10 @@ fun formPage(glossary: Glossary, onCancelClick: () -> Unit) {
openDialog.value = true
},
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
width = 150,
text = "Valider",
icon = Icons.Default.Check
)
) {
Icon(imageVector = Icons.Default.Check, contentDescription = null)
Text("Valider")
}
}
// Show the snackbar when the state is true
@ -384,15 +366,10 @@ fun formPage(glossary: Glossary, onCancelClick: () -> Unit) {
Snackbar(
modifier = Modifier.padding(16.dp),
action = {
Button(
buttonComponent(
onClick = { requiredFieldsSnackbarVisibleState.value = false },
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
)
) {
Text("OK")
}
width = 100,
text = "OK")
}
) {
Text("Les champs 'Mot' et 'Contexte principal' sont obligatoires.")
@ -402,15 +379,10 @@ fun formPage(glossary: Glossary, onCancelClick: () -> Unit) {
Snackbar(
modifier = Modifier.padding(16.dp),
action = {
Button(
buttonComponent(
onClick = { alreadyExistSnackbarVisibleState.value = false },
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
)
) {
Text("OK")
}
width = 100,
text = "OK")
}
) {
Text("Le mot '${name.value}' existe déjà dans le glossaire. Ajout annulé.")