Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.8 kB
1
Indexable
Never
@Composable
fun EditNoteScreen(
    viewModel: EditNoteScreenViewModel) {
    var isEditMode by remember { mutableStateOf(false) }

    Column(
        modifier = Modifier
            .fillMaxSize()
            .background(MaterialTheme.colorScheme.background)
            .padding(16.dp)
    ) {
        TextField(
            value = viewModel.title,
            onValueChange = { viewModel.updateTitle(it) },
            label = { Text("Title") },
            modifier = Modifier
                .fillMaxWidth()
                .padding(bottom = 16.dp)
        )

        TextField(
            value = viewModel.content,
            onValueChange = { viewModel.updateContent(it) },
            label = { Text("Note") },
            modifier = Modifier
                .fillMaxWidth()
                .height(200.dp)
                .padding(bottom = 16.dp)
        )

        Row(
            modifier = Modifier
                .fillMaxWidth()
                .padding(bottom = 16.dp),
            horizontalArrangement = Arrangement.End
        ) {
            if (isEditMode) {
                IconButton(
                    onClick = {
                        isEditMode = false
                        viewModel.updateNote()
                    }
                ) {
                    Icon(imageVector = Icons.Default.Done, contentDescription = "Save")
                }
            } else {
                IconButton(
                    onClick = {
                        isEditMode = true
                    //    viewModel.getNote(/* pass your note id here*/)
                    }
                ) {
                    Icon(imageVector = Icons.Default.Edit, contentDescription = "Edit")
                }
            }
        }
    }
}
Leave a Comment