ADD: Rename Collections
This commit is contained in:
parent
71d56519b2
commit
8e8eecf367
@ -44,6 +44,7 @@ import come.stormborntales.notevault.data.local.entity.NoteEntity
|
||||
fun CollectionItem(
|
||||
collection: NoteCollection,
|
||||
onDeleteCollection: (NoteCollection) -> Unit,
|
||||
onEditCollection: (NoteCollection) -> Unit,
|
||||
) {
|
||||
var showMenu by remember { mutableStateOf(false) }
|
||||
Box(
|
||||
@ -103,7 +104,7 @@ fun CollectionItem(
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
showMenu = false
|
||||
|
||||
onEditCollection(collection)
|
||||
},
|
||||
text = {
|
||||
Row(
|
||||
|
@ -62,10 +62,11 @@ import come.stormborntales.notevault.ui.viewmodel.NoteBrowserViewModel
|
||||
|
||||
@Composable
|
||||
fun CreateCollectionDialog(
|
||||
editedCollection: NoteCollection?,
|
||||
onDismiss: () -> Unit,
|
||||
onCreate: (String) -> Unit
|
||||
) {
|
||||
var collectionName by remember { mutableStateOf("") }
|
||||
var collectionName by remember { mutableStateOf(editedCollection?.name ?: "") }
|
||||
var isError by remember { mutableStateOf(false) }
|
||||
|
||||
AlertDialog(
|
||||
@ -165,7 +166,8 @@ fun NoteGrid(
|
||||
onNoteClick: (NoteEntity) -> Unit,
|
||||
onDeleteNote: (NoteEntity) -> Unit,
|
||||
onEditNote: (NoteEntity) ->Unit,
|
||||
onDeleteCollection: (NoteCollection) -> Unit
|
||||
onDeleteCollection: (NoteCollection) -> Unit,
|
||||
onEditCollection: (NoteCollection) -> Unit,
|
||||
) {
|
||||
var showCollectionConfirmationDialog by remember { mutableStateOf(false) }
|
||||
var deletedCollection: NoteCollection? by remember { mutableStateOf(null) }
|
||||
@ -180,7 +182,7 @@ fun NoteGrid(
|
||||
CollectionItem(collection, onDeleteCollection = {
|
||||
showCollectionConfirmationDialog = true
|
||||
deletedCollection = collection
|
||||
})
|
||||
}, onEditCollection = onEditCollection)
|
||||
}
|
||||
|
||||
items(notes) { note ->
|
||||
@ -204,7 +206,7 @@ fun NotesScreen(
|
||||
) {
|
||||
var menuExpanded by remember { mutableStateOf(false) }
|
||||
var showDialog by remember { mutableStateOf(false) }
|
||||
|
||||
var collectionToEdit by remember { mutableStateOf<NoteCollection?>(null) }
|
||||
|
||||
val collections by viewModel.currentCollections.collectAsState()
|
||||
val notes by viewModel.currentNotes.collectAsState()
|
||||
@ -273,6 +275,10 @@ fun NotesScreen(
|
||||
onEditNote = onEditNote,
|
||||
onDeleteCollection = {
|
||||
viewModel.removeCollection(noteCollection = it)
|
||||
},
|
||||
onEditCollection = {
|
||||
collectionToEdit = it
|
||||
showDialog = true
|
||||
}
|
||||
)
|
||||
|
||||
@ -284,9 +290,14 @@ fun NotesScreen(
|
||||
CreateCollectionDialog(
|
||||
onDismiss = { showDialog = false },
|
||||
onCreate = { name ->
|
||||
// Handle the new collection name
|
||||
viewModel.createCollection(name)
|
||||
}
|
||||
if(collectionToEdit != null) {
|
||||
viewModel.updateCollection(collectionToEdit!!, name)
|
||||
} else {
|
||||
// Handle the new collection name
|
||||
viewModel.createCollection(name)
|
||||
}
|
||||
},
|
||||
editedCollection = collectionToEdit
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -89,5 +89,15 @@ class NoteBrowserViewModel (
|
||||
loadContentForParent(newParentId)
|
||||
}
|
||||
|
||||
fun updateCollection(collectionToEdit: NoteCollection, name: String) {
|
||||
if(name.isNotEmpty()) {
|
||||
collectionToEdit.name = name
|
||||
viewModelScope.launch {
|
||||
collectionRepository.updateCollection(collectionToEdit)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user