From b42780ac92d3f064e2032a3e394e1c514934e825 Mon Sep 17 00:00:00 2001 From: CAPEL Maxime <83071634+fortyup@users.noreply.github.com> Date: Thu, 21 Dec 2023 12:37:15 +0100 Subject: [PATCH] Sonar lint on Home.kt --- src/main/kotlin/main/Home.kt | 73 ++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/src/main/kotlin/main/Home.kt b/src/main/kotlin/main/Home.kt index f9a6599..175a993 100644 --- a/src/main/kotlin/main/Home.kt +++ b/src/main/kotlin/main/Home.kt @@ -28,10 +28,8 @@ fun homePage( val appState = AppState val noFileSnackbarVisibleState = remember { mutableStateOf(false) } var isCompareClicked by remember { mutableStateOf(false) } - var selectedGlossary by remember { mutableStateOf(null) } - if (!isCompareClicked && selectedGlossary == null) { // Utilisez un Box pour placer le drapeau en haut à droite Box( @@ -88,7 +86,6 @@ fun homePage( onClick = { if (mostUsedWordList.isEmpty()) { noFileSnackbarVisibleState.value = true - println("Veuillez d'abord importer un fichier") return@Button } else { isCompareClicked = true @@ -137,7 +134,6 @@ fun homePage( "Comparer" -> { if (mostUsedWordList.isEmpty()) { noFileSnackbarVisibleState.value = true - println("Veuillez d'abord importer un fichier") return@dropdownButtonComponent } else { isCompareClicked = true @@ -149,40 +145,53 @@ fun homePage( var selectedProject by remember { mutableStateOf(null) } - if (isCompareClicked && selectedProject == null && selectedGlossary == null) { - projectList( - projects = loadProjects(), - onProjectSelected = { project -> - selectedProject = project - appState.selectedProject = selectedProject - println("selectedProject = $selectedProject") - }, - onBackClick = { isCompareClicked = false; selectedGlossary = null; selectedProject = null } - ) - - } else if (isCompareClicked && selectedGlossary == null) { - - glossaryList( - glossaries = loadGlossaries(appState.selectedProject!!), - onGlossarySelected = { glossary -> - selectedGlossary = glossary - println("selectedGlossary = $selectedGlossary") - }, - onBackClick = { isCompareClicked = false; selectedGlossary = null; selectedProject = null } - ) - } else if (isCompareClicked) { - selectedGlossary?.let { - compareResults( - glossaryWords = loadDatasFromFile(it.jsonFilePath), - codeWords = mostUsedWordList.keys.toList(), - onBackClick = { isCompareClicked = false; selectedGlossary = null; selectedProject = null } + when { + isCompareClicked && selectedProject == null && selectedGlossary == null -> { + projectList( + projects = loadProjects(), + onProjectSelected = { project -> + selectedProject = project + appState.selectedProject = selectedProject + }, + onBackClick = { + isCompareClicked = false + selectedGlossary = null + selectedProject = null + } ) } + isCompareClicked && selectedGlossary == null -> { + glossaryList( + glossaries = loadGlossaries(appState.selectedProject!!), + onGlossarySelected = { glossary -> + selectedGlossary = glossary + }, + onBackClick = { + isCompareClicked = false + selectedGlossary = null + selectedProject = null + } + ) + } + + isCompareClicked -> { + selectedGlossary?.let { + compareResults( + glossaryWords = loadDatasFromFile(it.jsonFilePath), + codeWords = mostUsedWordList.keys.toList(), + onBackClick = { + isCompareClicked = false + selectedGlossary = null + selectedProject = null + } + ) + } + } } } -@Composable + @Composable fun glossaryList(glossaries: List, onGlossarySelected: (Glossary) -> Unit, onBackClick: () -> Unit) { Column( modifier = Modifier.fillMaxSize(),