|
@@ -19,6 +19,7 @@ import androidx.compose.material3.DropdownMenuItem
|
|
|
import androidx.compose.material3.Text
|
|
|
import androidx.compose.material3.TextField
|
|
|
import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.LaunchedEffect
|
|
|
import androidx.compose.runtime.MutableState
|
|
|
import androidx.compose.runtime.collectAsState
|
|
|
import androidx.compose.runtime.getValue
|
|
@@ -37,20 +38,28 @@ import androidx.navigation.NavHostController
|
|
|
import com.example.collectionofshortstories.view.authorization.AuthorizationViewModel
|
|
|
import com.example.collectionofshortstories.view.authorization.CreateTextFolder
|
|
|
|
|
|
-
|
|
|
@Composable
|
|
|
fun СreateArticle(
|
|
|
navHostController: NavHostController,
|
|
|
viewModel: СreateArticleViewModel = hiltViewModel()
|
|
|
) {
|
|
|
var expanded by remember { mutableStateOf(false) }
|
|
|
- var selectedItem by remember { mutableStateOf("Выберите категорию") }
|
|
|
+ var selectedCategory by remember { mutableStateOf("Выберите категорию") }
|
|
|
+ var textArticle = remember { mutableStateOf("") }
|
|
|
+ var title = remember { mutableStateOf("") }
|
|
|
+
|
|
|
val listCategories by viewModel.categories.collectAsState(initial = emptyList())
|
|
|
|
|
|
+ LaunchedEffect(key1 = viewModel.navigationTo) {
|
|
|
+ viewModel.navigationTo.collect { destination ->
|
|
|
+ destination?.let {
|
|
|
+ navHostController.navigate(destination)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
viewModel.GetCategories()
|
|
|
|
|
|
- val title = remember { mutableStateOf("") }
|
|
|
- val category = remember { mutableStateOf("") }
|
|
|
Column(
|
|
|
horizontalAlignment = Alignment.CenterHorizontally,
|
|
|
modifier = Modifier
|
|
@@ -68,7 +77,7 @@ fun СreateArticle(
|
|
|
fontSize = 30.sp,
|
|
|
fontWeight = FontWeight.Bold,
|
|
|
modifier = Modifier
|
|
|
- .padding(0.dp, 50.dp, 0.dp, 30.dp)
|
|
|
+ .padding(0.dp, 30.dp, 0.dp, 30.dp)
|
|
|
)
|
|
|
Divider(
|
|
|
modifier = Modifier.fillMaxWidth(),
|
|
@@ -84,55 +93,61 @@ fun СreateArticle(
|
|
|
color = Color.Black,
|
|
|
fontSize = 30.sp
|
|
|
)
|
|
|
- Row(
|
|
|
- horizontalArrangement = Arrangement.spacedBy(10.dp),
|
|
|
- modifier = Modifier.fillMaxWidth()
|
|
|
+
|
|
|
+ TextField(
|
|
|
+ value = title.value,
|
|
|
+ onValueChange = { titleNew -> title.value = titleNew },
|
|
|
+ maxLines = 1,
|
|
|
+ placeholder = { Text("Название") },
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(0.dp, 30.dp, 0.dp, 0.dp)
|
|
|
+ )
|
|
|
+ TextField(
|
|
|
+ value = textArticle.value,
|
|
|
+ onValueChange = { textArticleNew -> textArticle.value = textArticleNew },
|
|
|
+ maxLines = 1,
|
|
|
+ placeholder = { Text("Текст рассказа") },
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(0.dp, 30.dp, 0.dp, 0.dp)
|
|
|
+ .weight(6f)
|
|
|
+ )
|
|
|
+
|
|
|
+ Button(
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(0.dp, 10.dp),
|
|
|
+ onClick = { expanded = !expanded }
|
|
|
) {
|
|
|
- TextField(
|
|
|
- value = title.value,
|
|
|
- onValueChange = { newEmail -> title.value = newEmail },
|
|
|
- maxLines = 1,
|
|
|
- placeholder = { Text("Название") },
|
|
|
- modifier = Modifier
|
|
|
- .padding(0.dp, 30.dp, 0.dp, 0.dp)
|
|
|
- .weight(2f)
|
|
|
- )
|
|
|
- Column (
|
|
|
- ) {
|
|
|
- Button(
|
|
|
- onClick = { expanded = !expanded }
|
|
|
- ) {
|
|
|
- Text(text = selectedItem)
|
|
|
- }
|
|
|
- DropdownMenu(
|
|
|
- expanded = expanded,
|
|
|
- onDismissRequest = { expanded = false },
|
|
|
+ Text(text = selectedCategory)
|
|
|
+ }
|
|
|
+ DropdownMenu(
|
|
|
+ expanded = expanded,
|
|
|
+ onDismissRequest = { expanded = false },
|
|
|
|
|
|
- ) {
|
|
|
- for (categories in listCategories) {
|
|
|
- DropdownMenuItem(onClick = {
|
|
|
- selectedItem = categories.title
|
|
|
- expanded = false
|
|
|
- },
|
|
|
- text = { Text(categories.title) }
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
+ ) {
|
|
|
+ for (categories in listCategories) {
|
|
|
+ DropdownMenuItem(onClick = {
|
|
|
+ selectedCategory = categories.title
|
|
|
+ expanded = false
|
|
|
+ },
|
|
|
+ text = { Text(categories.title) }
|
|
|
+ )
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
Button(
|
|
|
onClick = {
|
|
|
+ viewModel.InsertNewArticle(title.value, textArticle.value, selectedCategory)
|
|
|
+ },
|
|
|
+ colors = ButtonDefaults.buttonColors(
|
|
|
+ containerColor = Color(0xFFFCE0C6)
|
|
|
+ ),
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .padding(40.dp, 20.dp)
|
|
|
+ .border(BorderStroke(2.dp, Color.Black), shape = RoundedCornerShape(25.dp))
|
|
|
|
|
|
- },
|
|
|
- colors = ButtonDefaults.buttonColors(
|
|
|
- containerColor = Color(0xFFFCE0C6)
|
|
|
- ),
|
|
|
- modifier = Modifier
|
|
|
- .fillMaxWidth()
|
|
|
- .padding(40.dp, 20.dp)
|
|
|
- .border(BorderStroke(2.dp, Color.Black), shape = RoundedCornerShape(25.dp))
|
|
|
-
|
|
|
- ) {
|
|
|
+ ) {
|
|
|
Text(
|
|
|
text = "Сохранить рассказ",
|
|
|
color = Color.Black
|
|
@@ -143,26 +158,3 @@ fun СreateArticle(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Composable
|
|
|
- fun CreateTextFolder(
|
|
|
- titleState: MutableState<String>,
|
|
|
- categoryState: MutableState<String>
|
|
|
- ) {
|
|
|
- TextField(
|
|
|
- value = titleState.value,
|
|
|
- onValueChange = { newEmail -> titleState.value = newEmail },
|
|
|
- maxLines = 1,
|
|
|
- placeholder = { Text("Название") },
|
|
|
- modifier = Modifier
|
|
|
- .padding(0.dp, 30.dp, 0.dp, 0.dp)
|
|
|
-
|
|
|
- )
|
|
|
- TextField(
|
|
|
- value = categoryState.value,
|
|
|
- onValueChange = { newPass -> categoryState.value = newPass },
|
|
|
- maxLines = 1,
|
|
|
- placeholder = { Text("Категория рассказа") },
|
|
|
- modifier = Modifier
|
|
|
- .padding(0.dp, 30.dp, 0.dp, 0.dp)
|
|
|
- )
|
|
|
- }
|