diff --git a/src/main/kotlin/main/CompareGlossary.kt b/src/main/kotlin/main/CompareGlossary.kt index bebcf18..9911a99 100644 --- a/src/main/kotlin/main/CompareGlossary.kt +++ b/src/main/kotlin/main/CompareGlossary.kt @@ -26,6 +26,7 @@ fun glossaryList( ) { var isCompareClicked by remember { mutableStateOf(false) } + var selectedGlossary by remember { mutableStateOf(null) } val noFileSnackbarVisibleState = remember { mutableStateOf(false) } Column( @@ -62,7 +63,13 @@ fun glossaryList( horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { - buttonComponent(glossary.name, { onGlossarySelected(glossary) }, width = 200) + buttonComponent( + glossary.name, + { + onGlossarySelected(glossary) + currentPage.value = "compareTable" + } + ) } } } @@ -96,4 +103,10 @@ fun glossaryList( } } } + + when { + isCompareClicked && selectedGlossary == null -> { + currentPage.value = "compareGlossary" + } + } } \ No newline at end of file diff --git a/src/main/kotlin/main/CompareProject.kt b/src/main/kotlin/main/CompareProject.kt index 1c285e1..925cb91 100644 --- a/src/main/kotlin/main/CompareProject.kt +++ b/src/main/kotlin/main/CompareProject.kt @@ -62,7 +62,13 @@ fun projectList( horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically ) { - buttonComponent(project.name, { onProjectSelected(project) }, width = 200) + buttonComponent( + project.name, + { + onProjectSelected(project) + currentPage.value = "compareGlossary" + } + ) } } } diff --git a/src/main/kotlin/main/Home.kt b/src/main/kotlin/main/Home.kt index a64699e..f8fc7a0 100644 --- a/src/main/kotlin/main/Home.kt +++ b/src/main/kotlin/main/Home.kt @@ -1,10 +1,8 @@ package main -import androidx.compose.foundation.* +import androidx.compose.foundation.Image +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* -import androidx.compose.foundation.lazy.LazyColumn -import androidx.compose.foundation.lazy.items -import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment @@ -25,9 +23,9 @@ enum class Language { fun homePage( languageManager: LanguageManager, onProjectClick: () -> Unit, - onCodeToVerifyClick: () -> Unit + onCodeToVerifyClick: () -> Unit, + onCompareClick: () -> Unit, ) { - val appState = AppState val noFileSnackbarVisibleState = remember { mutableStateOf(false) } var isCompareClicked by remember { mutableStateOf(false) } var selectedGlossary by remember { mutableStateOf(null) } @@ -83,7 +81,7 @@ fun homePage( noFileSnackbarVisibleState.value = true return@Button } else { - isCompareClicked = true + onCompareClick() } }, modifier = Modifier.width(200.dp), @@ -124,69 +122,12 @@ fun homePage( noFileSnackbarVisibleState.value = true return@dropdownButtonComponent } else { - isCompareClicked = true + currentPage.value = "compareProject" } } } } } - var selectedProject by remember { mutableStateOf(null) } - - - when { - isCompareClicked && selectedProject == null && selectedGlossary == null -> { - projectList( - projects = loadProjects(), - onProjectSelected = { project -> - selectedProject = project - appState.selectedProject = selectedProject - }, - onBackClick = { - isCompareClicked = false - selectedGlossary = null - selectedProject = null - }, - onProjectClick = { currentPage.value = "projects" }, - languageManager = languageManager, - onCodeToVerifyClick = { currentPage.value = "choixLangage" } - ) - } - - isCompareClicked && selectedGlossary == null -> { - glossaryList( - glossaries = loadGlossaries(appState.selectedProject!!), - onGlossarySelected = { glossary -> - selectedGlossary = glossary - }, - onBackClick = { - isCompareClicked = false - selectedGlossary = null - selectedProject = null - }, - onProjectClick = { currentPage.value = "projects" }, - languageManager = languageManager, - onCodeToVerifyClick = { currentPage.value = "choixLangage" } - ) - } - - isCompareClicked -> { - selectedGlossary?.let { - compareResults( - languageManager = languageManager, - glossaryWords = loadDatasFromFile(it.jsonFilePath), - codeWords = mostUsedWordList.keys.toList(), - onBackClick = { - isCompareClicked = false - selectedGlossary = null - selectedProject = null - }, - onProjectClick = { currentPage.value = "projects" }, - onCodeToVerifyClick = { currentPage.value = "choixLangage" }, - ) - - } - } - } HelpButton { showHelpPage = true diff --git a/src/main/kotlin/main/Main.kt b/src/main/kotlin/main/Main.kt index c8c6063..965d2b4 100644 --- a/src/main/kotlin/main/Main.kt +++ b/src/main/kotlin/main/Main.kt @@ -5,12 +5,12 @@ import androidx.compose.foundation.layout.padding import androidx.compose.material.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment -import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp import androidx.compose.ui.window.* +import main.AppState.selectedGlossary import java.awt.FileDialog import java.awt.Frame import java.io.File @@ -29,7 +29,7 @@ object AppState { var selectedGlossary: Glossary? = null } -@OptIn(ExperimentalMaterialApi::class, ExperimentalComposeUiApi::class) +@OptIn(ExperimentalMaterialApi::class) @Composable @Preview fun app() { @@ -53,6 +53,7 @@ fun app() { languageManager, onProjectClick = { currentPage.value = "projects" }, onCodeToVerifyClick = { currentPage.value = "choixLangage" }, + onCompareClick = { currentPage.value = "compareProject" }, ) } @@ -83,6 +84,52 @@ fun app() { ) } + "compareProject" -> { + var selectedProject by remember { mutableStateOf(null) } + projectList( + projects = loadProjects(), + onProjectSelected = { project -> + selectedProject = project + appState.selectedProject = selectedProject + }, + onBackClick = { + currentPage.value = "accueil" + }, + onProjectClick = { currentPage.value = "projects" }, + languageManager = languageManager, + onCodeToVerifyClick = { currentPage.value = "choixLangage" } + ) + } + + "compareGlossary" -> { + var selectedGlossary by remember { mutableStateOf(null) } + glossaryList( + glossaries = loadGlossaries(appState.selectedProject!!), + onGlossarySelected = { glossary -> + selectedGlossary = glossary + }, + onBackClick = { + currentPage.value = "compareProject" + }, + onProjectClick = { currentPage.value = "projects" }, + languageManager = languageManager, + onCodeToVerifyClick = { currentPage.value = "choixLangage" } + ) + } + + "compareTable" -> { + compareResults( + languageManager = languageManager, + glossaryWords = selectedGlossary?.jsonFilePath?.let { loadDatasFromFile(it) } ?: emptyList(), + codeWords = mostUsedWordList.keys.toList(), + onBackClick = { + currentPage.value = "compareGlossary" + }, + onProjectClick = { currentPage.value = "projects" }, + onCodeToVerifyClick = { currentPage.value = "choixLangage" }, + ) + } + "nouveauProjet" ->{ newProject( languageManager, diff --git a/src/main/kotlin/main/Verify.kt b/src/main/kotlin/main/Verify.kt index 6fe68a0..c383209 100644 --- a/src/main/kotlin/main/Verify.kt +++ b/src/main/kotlin/main/Verify.kt @@ -1,10 +1,7 @@ package main import androidx.compose.foundation.layout.* -import androidx.compose.material.Button -import androidx.compose.material.ButtonDefaults -import androidx.compose.material.MaterialTheme -import androidx.compose.material.Text +import androidx.compose.material.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.runtime.* @@ -131,7 +128,7 @@ fun choixLangagePage( noFileSnackbarVisibleState.value = true return@dropdownButtonComponent } else { - isCompareClicked = true + currentPage.value = "compareProject" } } }