diff --git a/src/main/kotlin/main/Form.kt b/src/main/kotlin/main/Form.kt index b6eb60b..fa57ae3 100644 --- a/src/main/kotlin/main/Form.kt +++ b/src/main/kotlin/main/Form.kt @@ -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 - ) - ) { - Text("Fermer") - - } + width = 100, + 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 - ) - ) { - Icon(imageVector = Icons.Default.Check, contentDescription = null) - Text("Valider") - } + width = 150, + text = "Valider", + icon = Icons.Default.Check + ) } // 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é.") diff --git a/src/main/kotlin/main/Home.kt b/src/main/kotlin/main/Home.kt index 5132219..25eb2da 100644 --- a/src/main/kotlin/main/Home.kt +++ b/src/main/kotlin/main/Home.kt @@ -166,7 +166,7 @@ fun homePage( } } - @Composable +@Composable fun glossaryList(glossaries: List, onGlossarySelected: (Glossary) -> Unit, onBackClick: () -> Unit) { Column( modifier = Modifier.fillMaxSize(),