Update newGlossary View
parent
e331578e01
commit
29368a1688
|
@ -136,7 +136,7 @@ fun glossariesPage(
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
currentPage.value = "accueil"
|
currentPage.value = "projects"
|
||||||
},
|
},
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(250.dp),
|
.width(250.dp),
|
||||||
|
@ -160,64 +160,57 @@ fun newGlossary(
|
||||||
val glossaryAlreadyExistsSnackbarVisibleState = remember { mutableStateOf(false) }
|
val glossaryAlreadyExistsSnackbarVisibleState = remember { mutableStateOf(false) }
|
||||||
val invalidCharacterSnackbarVisibleState = remember { mutableStateOf(false) }
|
val invalidCharacterSnackbarVisibleState = remember { mutableStateOf(false) }
|
||||||
|
|
||||||
var nouveauGlossaireName by remember { mutableStateOf("") }
|
|
||||||
var glossaries by remember { mutableStateOf(emptyList<Glossary>()) }
|
var glossaries by remember { mutableStateOf(emptyList<Glossary>()) }
|
||||||
|
|
||||||
|
var nouveauGlossaireName by remember { mutableStateOf("") }
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
verticalArrangement = Arrangement.Center,
|
verticalArrangement = Arrangement.Center,
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
|
Text("Nom du glossaire", style = MaterialTheme.typography.h5)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
TextField(
|
TextField(
|
||||||
value = nouveauGlossaireName,
|
value = nouveauGlossaireName,
|
||||||
onValueChange = { nouveauGlossaireName = it },
|
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
label = { Text("Nom du nouveau glossaire") },
|
onValueChange = { nouveauGlossaireName = it },
|
||||||
|
label = { Text("Nom du glossaire") },
|
||||||
|
colors = TextFieldDefaults.textFieldColors(
|
||||||
|
focusedIndicatorColor = customRedColor,
|
||||||
|
unfocusedIndicatorColor = Color.Gray,
|
||||||
|
focusedLabelColor = customRedColor
|
||||||
|
),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(16.dp)
|
.width(300.dp)
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.onKeyEvent { event ->
|
.onKeyEvent { event ->
|
||||||
if (event.key == Key.Enter && event.type == KeyEventType.KeyDown) {
|
if (event.key == Key.Enter && event.type == KeyEventType.KeyDown) {
|
||||||
// Handle the Enter key event by calling the common function
|
if (nouveauGlossaireName.isEmpty()) {
|
||||||
when {
|
|
||||||
nouveauGlossaireName.isEmpty() -> {
|
|
||||||
println("Veuillez saisir un nom pour le nouveau glossaire")
|
println("Veuillez saisir un nom pour le nouveau glossaire")
|
||||||
isEmptySnackbarVisibleState.value = true
|
isEmptySnackbarVisibleState.value = true
|
||||||
}
|
} else if (nouveauGlossaireName.contains(" ")) {
|
||||||
nouveauGlossaireName.contains(" ") -> {
|
|
||||||
println("Le nom du glossaire ne doit pas contenir d'espace")
|
println("Le nom du glossaire ne doit pas contenir d'espace")
|
||||||
containsSpaceSnackbarVisibleState.value = true
|
containsSpaceSnackbarVisibleState.value = true
|
||||||
}
|
} else if (glossaries.any { it.name == nouveauGlossaireName }) {
|
||||||
glossaries.any { it.name == nouveauGlossaireName } -> {
|
|
||||||
println("Le nom du glossaire existe déjà")
|
println("Le nom du glossaire existe déjà")
|
||||||
glossaryAlreadyExistsSnackbarVisibleState.value = true
|
glossaryAlreadyExistsSnackbarVisibleState.value = true
|
||||||
}
|
} else if (!isValidFileName(nouveauGlossaireName)) {
|
||||||
!isValidFileName(nouveauGlossaireName) -> {
|
|
||||||
println("Le nom du glossaire contient des caractères non autorisés")
|
println("Le nom du glossaire contient des caractères non autorisés")
|
||||||
invalidCharacterSnackbarVisibleState.value = true
|
invalidCharacterSnackbarVisibleState.value = true
|
||||||
}
|
} else {
|
||||||
else -> {
|
val directory = File("src/main/resources/projects/${appState.selectedProject}/$nouveauGlossaireName")
|
||||||
val newGlossary = Glossary(nouveauGlossaireName, "$nouveauGlossaireName.json")
|
directory.mkdirs()
|
||||||
glossaries = glossaries + newGlossary
|
println("Project $nouveauGlossaireName created")
|
||||||
// create new json file
|
currentPage.value = "projects"
|
||||||
val newFile =
|
|
||||||
File(glossaryPath + (appState.selectedProject?.name) + "/" + newGlossary.jsonFilePath)
|
|
||||||
newFile.createNewFile()
|
|
||||||
// update glossaries list
|
|
||||||
glossaries = loadGlossaries(appState.selectedProject!!)
|
|
||||||
currentPage.value = "glossaires" // Revenir à la liste des glossaires
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
colors = TextFieldDefaults.textFieldColors(
|
|
||||||
backgroundColor = Color.White,
|
|
||||||
focusedIndicatorColor = customRedColor,
|
|
||||||
unfocusedIndicatorColor = Color.Gray
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
|
|
Loading…
Reference in New Issue