Add ScrollBar on ProjectList

main
Thomas Breil 2024-01-12 15:34:59 +01:00
parent 6631008fcc
commit 60d7cf84c6
2 changed files with 79 additions and 54 deletions

View File

@ -188,23 +188,34 @@ fun newGlossary(
.fillMaxWidth() .fillMaxWidth()
.onKeyEvent { event -> .onKeyEvent { event ->
if (event.key == Key.Enter && event.type == KeyEventType.KeyDown) { if (event.key == Key.Enter && event.type == KeyEventType.KeyDown) {
if (nouveauGlossaireName.isEmpty()) { when {
println("Veuillez saisir un nom pour le nouveau glossaire") nouveauGlossaireName.isEmpty() -> {
isEmptySnackbarVisibleState.value = true println("Veuillez saisir un nom pour le nouveau glossaire")
} else if (nouveauGlossaireName.contains(" ")) { isEmptySnackbarVisibleState.value = true
println("Le nom du glossaire ne doit pas contenir d'espace") }
containsSpaceSnackbarVisibleState.value = true nouveauGlossaireName.contains(" ") -> {
} else if (glossaries.any { it.name == nouveauGlossaireName }) { println("Le nom du glossaire ne doit pas contenir d'espace")
println("Le nom du glossaire existe déjà") containsSpaceSnackbarVisibleState.value = true
glossaryAlreadyExistsSnackbarVisibleState.value = true }
} else if (!isValidFileName(nouveauGlossaireName)) { glossaries.any { it.name == nouveauGlossaireName } -> {
println("Le nom du glossaire contient des caractères non autorisés") println("Le nom du glossaire existe déjà")
invalidCharacterSnackbarVisibleState.value = true glossaryAlreadyExistsSnackbarVisibleState.value = true
} else { }
val directory = File("src/main/resources/projects/${appState.selectedProject}/$nouveauGlossaireName") !isValidFileName(nouveauGlossaireName) -> {
directory.mkdirs() println("Le nom du glossaire contient des caractères non autorisés")
println("Project $nouveauGlossaireName created") invalidCharacterSnackbarVisibleState.value = true
currentPage.value = "projects" }
else -> {
val newGlossary = Glossary(nouveauGlossaireName, "$nouveauGlossaireName.json")
glossaries = glossaries + newGlossary
// create new json file
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 {

View File

@ -1,8 +1,11 @@
package main package main
import androidx.compose.foundation.VerticalScrollbar
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollbarAdapter
import androidx.compose.material.* import androidx.compose.material.*
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete import androidx.compose.material.icons.filled.Delete
@ -39,54 +42,65 @@ fun projectsPage(
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
LazyColumn( Box(
modifier = Modifier modifier = Modifier
.height(300.dp)
.width(250.dp)
.padding(10.dp) .padding(10.dp)
.width(200.dp)
.height(300.dp),
verticalArrangement = Arrangement.spacedBy(10.dp)
) { ) {
val scrollState = rememberLazyListState()
projects = loadProjects()
if (projects.isEmpty()) { if (projects.isEmpty()) {
item { Text("Aucun proje n'a été créé")
Text("Aucun projet n'a été créé")
}
} else { } else {
items(projects, key = { project -> project.name }) { project -> LazyColumn(
Row( state = scrollState,
modifier = Modifier.width(200.dp).fillMaxWidth(), modifier = Modifier.padding(10.dp),
horizontalArrangement = Arrangement.SpaceBetween verticalArrangement = Arrangement.spacedBy(10.dp)
) { ) {
Button( println(projects)
onClick = { items(projects) { project ->
appState.selectedProject = project Row(
currentPage.value = "glossaires" modifier = Modifier.width(200.dp).fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
},
modifier = Modifier
.width(150.dp),
colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor,
contentColor = Color.White
)
) { ) {
Text(project.name) Button(
} onClick = {
main.appState.selectedProject = project
IconButton( currentPage.value = "glossaires"
onClick = { },
// Handle delete project action modifier = Modifier
projects = projects.filterNot { it.name == project.name } .width(150.dp),
println(projects) colors = ButtonDefaults.buttonColors(
val directory = File("src/main/resources/projects/${project.name}/") backgroundColor = customRedColor,
directory.deleteRecursively() contentColor = Color.White
currentPage.value = "projects" )
) {
Text(project.name)
}
IconButton(
onClick = {
// Handle delete glossary action
projects = projects.filterNot { it == project }
val directory = File("src/main/resources/projects/${project.name}/")
directory.deleteRecursively()
currentPage.value = "projects"
}
) {
Icon(
imageVector = Icons.Default.Delete,
contentDescription = "Delete Project"
)
} }
) {
Icon(imageVector = Icons.Default.Delete, contentDescription = "Delete Project")
} }
} }
} }
} }
VerticalScrollbar(
modifier = Modifier.align(Alignment.CenterEnd).fillMaxHeight(),
adapter = rememberScrollbarAdapter(scrollState)
)
} }
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))