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

View File

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