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 {
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 { }
val directory = File("src/main/resources/projects/${appState.selectedProject}/$nouveauGlossaireName") else -> {
directory.mkdirs() val newGlossary = Glossary(nouveauGlossaireName, "$nouveauGlossaireName.json")
println("Project $nouveauGlossaireName created") glossaries = glossaries + newGlossary
currentPage.value = "projects" // 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,28 +42,32 @@ 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), val scrollState = rememberLazyListState()
projects = loadProjects()
if (projects.isEmpty()) {
Text("Aucun proje n'a été créé")
} else {
LazyColumn(
state = scrollState,
modifier = Modifier.padding(10.dp),
verticalArrangement = Arrangement.spacedBy(10.dp) verticalArrangement = Arrangement.spacedBy(10.dp)
) { ) {
if (projects.isEmpty()) { println(projects)
item { items(projects) { project ->
Text("Aucun projet n'a été créé")
}
} else {
items(projects, key = { project -> project.name }) { project ->
Row( Row(
modifier = Modifier.width(200.dp).fillMaxWidth(), modifier = Modifier.width(200.dp).fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween horizontalArrangement = Arrangement.SpaceBetween
) { ) {
Button( Button(
onClick = { onClick = {
appState.selectedProject = project main.appState.selectedProject = project
currentPage.value = "glossaires" currentPage.value = "glossaires"
}, },
modifier = Modifier modifier = Modifier
.width(150.dp), .width(150.dp),
@ -74,20 +81,27 @@ fun projectsPage(
IconButton( IconButton(
onClick = { onClick = {
// Handle delete project action // Handle delete glossary action
projects = projects.filterNot { it.name == project.name } projects = projects.filterNot { it == project }
println(projects)
val directory = File("src/main/resources/projects/${project.name}/") val directory = File("src/main/resources/projects/${project.name}/")
directory.deleteRecursively() directory.deleteRecursively()
currentPage.value = "projects" 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))