From 9c9906df162690108982b74c1a5770b3a9e9b76c Mon Sep 17 00:00:00 2001 From: CAPEL Maxime <83071634+fortyup@users.noreply.github.com> Date: Thu, 7 Dec 2023 14:42:12 +0100 Subject: [PATCH] Remove code duplication --- src/main/kotlin/main/Main.kt | 40 +++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/main/Main.kt b/src/main/kotlin/main/Main.kt index f7c2bf7..75578b9 100644 --- a/src/main/kotlin/main/Main.kt +++ b/src/main/kotlin/main/Main.kt @@ -7,6 +7,7 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Check import androidx.compose.material.icons.filled.Close import androidx.compose.runtime.Composable +import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Alignment @@ -205,11 +206,11 @@ fun exportToCSV(csvFilePath: String) { fun importFile(cheminFichier: String) { val fileExtension = File(cheminFichier).extension.lowercase() - when { - fileExtension == "csv" -> { + when (fileExtension) { + "csv" -> { importCSVFile(cheminFichier) } - fileExtension == "xlsx" -> { + "xlsx" -> { importXLSXFile(cheminFichier) } else -> { @@ -494,6 +495,23 @@ fun glossairePage( } +fun resetFields( + nom: MutableState, + description: MutableState, + contextePrincipal: MutableState, + contexte2: MutableState, + lieA: MutableState, + synonyme: MutableState, + antonyme: MutableState +) { + nom.value = "" + description.value = "" + contextePrincipal.value = "" + contexte2.value = "" + lieA.value = "" + synonyme.value = "" + antonyme.value = "" +} @OptIn(ExperimentalMaterialApi::class) @Composable @@ -525,13 +543,7 @@ fun formulairePage(onAnnulerClick: () -> Unit) { Button( onClick = { openDialog.value = false - nom.value = "" - description.value = "" - contextePrincipal.value = "" - contexte2.value = "" - lieA.value = "" - synonyme.value = "" - antonyme.value = "" + resetFields(nom, description, contextePrincipal, contexte2, lieA, synonyme, antonyme) }, colors = ButtonDefaults.buttonColors( @@ -657,13 +669,7 @@ fun formulairePage(onAnnulerClick: () -> Unit) { openDialog.value = true // Réinitialiser les champs après l'ajout - nom.value = "" - description.value = "" - contextePrincipal.value = "" - contexte2.value = "" - lieA.value = "" - synonyme.value = "" - antonyme.value = "" + resetFields(nom, description, contextePrincipal, contexte2, lieA, synonyme, antonyme) }, colors = ButtonDefaults.buttonColors(