From 6f1ac6f912f12d5fdc2d8f1eac1d339207ed3dea Mon Sep 17 00:00:00 2001 From: "Gleb O. Ivaniczkij" Date: Sun, 1 Sep 2024 23:49:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D1=86=D0=B5=D0=BD=D0=B0=D1=80=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=B0=D0=B4=D0=B0=D0=BF=D1=82=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D1=8B=20=D0=BF=D0=BE=D0=B4=20=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D1=83=D1=8E=20=D1=81=D1=85=D0=B5=D0=BC=D1=83=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cit_is_bot/ui/dialogs/ScenarioDialog.kt | 684 +++++++++--------- .../cit_is_bot/ui/screens/ScenariosScreen.kt | 38 +- 2 files changed, 377 insertions(+), 345 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/ui/dialogs/ScenarioDialog.kt b/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/ui/dialogs/ScenarioDialog.kt index cd2cde2..1bc7ab0 100644 --- a/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/ui/dialogs/ScenarioDialog.kt +++ b/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/ui/dialogs/ScenarioDialog.kt @@ -102,7 +102,7 @@ fun ScenarioDialog( mutableStateOf(scenarioDialogState.value?.name) } val timeState = remember { - mutableStateOf(scenarioDialogState.value?.time) + mutableStateOf(scenarioDialogState.value?.startTime) } Dialog( @@ -393,354 +393,360 @@ fun ScenarioDialog( modifier = Modifier .height(16.dp), ) - Card( - colors = CardDefaults.cardColors( - containerColor = MaterialTheme.colorScheme.surfaceContainer, + + } + } + } +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun MessageCard() { + Card( + colors = CardDefaults.cardColors( + containerColor = MaterialTheme.colorScheme.surfaceContainer, + ), + ) { + val dropdownMenuState = remember { + mutableStateOf(false) + } + val messageTypeState = remember { + mutableStateOf(MessageType.TEXT) + } + Column( + modifier = Modifier + .padding(16.dp), + ) { + Text( + text = "Общее", + style = MaterialTheme.typography.titleMedium, + ) + Spacer( + modifier = Modifier + .height(8.dp), + ) + OutlinedTextField( + value = "", + onValueChange = {}, + modifier = Modifier + .fillMaxWidth(), + label = { + Text( + text = "Название", + ) + }, + leadingIcon = { + Icon( + painter = painterResource(Res.drawable.baseline_title_24), + contentDescription = null, + ) + }, + supportingText = { + Text( + text = "Отображается в списке переходов", + ) + }, + isError = false, + singleLine = true, + ) + Spacer( + modifier = Modifier + .height(8.dp), + ) + OutlinedTextField( + value = "", + onValueChange = {}, + modifier = Modifier + .fillMaxWidth(), + label = { + Text( + text = "Время окончания", + ) + }, + leadingIcon = { + Icon( + painter = painterResource(Res.drawable.outline_time_auto_24), + contentDescription = null, + ) + }, + supportingText = { + Text( + text = "Время прекращения обработки событий", + ) + }, + isError = false, + singleLine = true, + ) + Spacer( + modifier = Modifier + .height(8.dp), + ) + val disableNotificationCheckboxState = remember { + mutableStateOf(false) + } + TextCheckbox( + text = "Не отправлять уведомление", + checkboxState = disableNotificationCheckboxState, + ) + val deleteAfterEndCheckboxState = remember { + mutableStateOf(false) + } + TextCheckbox( + text = "Удалить после окончания", + checkboxState = deleteAfterEndCheckboxState, + ) + Spacer( + modifier = Modifier + .height(8.dp), + ) + ExposedDropdownMenuBox( + expanded = dropdownMenuState.value, + onExpandedChange = { value -> + dropdownMenuState.value = value + }, + modifier = Modifier + .pointerHoverIcon( + icon = PointerIcon.Default, + overrideDescendants = true, ), - ) { - val dropdownMenuState = remember { - mutableStateOf(false) - } - val messageTypeState = remember { - mutableStateOf(MessageType.TEXT) - } - Column( - modifier = Modifier - .padding(16.dp), - ) { + ) { + OutlinedTextField( + value = messageTypeState.value.displayName, + onValueChange = {}, + modifier = Modifier + .fillMaxWidth() + .menuAnchor(), + label = { Text( - text = "Общее", - style = MaterialTheme.typography.titleMedium, + text = "Тип", ) - Spacer( - modifier = Modifier - .height(8.dp), + }, + readOnly = true, + leadingIcon = { + Icon( + painter = painterResource(messageTypeState.value.icon), + contentDescription = null, ) - OutlinedTextField( - value = "", - onValueChange = {}, - modifier = Modifier - .fillMaxWidth(), - label = { - Text( - text = "Название", - ) - }, - leadingIcon = { - Icon( - painter = painterResource(Res.drawable.baseline_title_24), - contentDescription = null, - ) - }, - supportingText = { - Text( - text = "Отображается в списке переходов", - ) - }, - isError = false, - singleLine = true, - ) - Spacer( - modifier = Modifier - .height(8.dp), - ) - OutlinedTextField( - value = "", - onValueChange = {}, - modifier = Modifier - .fillMaxWidth(), - label = { - Text( - text = "Время окончания", - ) - }, - leadingIcon = { - Icon( - painter = painterResource(Res.drawable.outline_time_auto_24), - contentDescription = null, - ) - }, - supportingText = { - Text( - text = "Время прекращения обработки событий", - ) - }, - isError = false, - singleLine = true, - ) - Spacer( - modifier = Modifier - .height(8.dp), - ) - val disableNotificationCheckboxState = remember { - mutableStateOf(false) - } - TextCheckbox( - text = "Не отправлять уведомление", - checkboxState = disableNotificationCheckboxState, - ) - val deleteAfterEndCheckboxState = remember { - mutableStateOf(false) - } - TextCheckbox( - text = "Удалить после окончания", - checkboxState = deleteAfterEndCheckboxState, - ) - Spacer( - modifier = Modifier - .height(8.dp), - ) - ExposedDropdownMenuBox( + }, + trailingIcon = { + ExposedDropdownMenuDefaults.TrailingIcon( expanded = dropdownMenuState.value, - onExpandedChange = { value -> - dropdownMenuState.value = value + ) + }, + isError = false, + singleLine = true, + ) + ExposedDropdownMenu( + expanded = dropdownMenuState.value, + onDismissRequest = { + dropdownMenuState.value = false + }, + ) { + MessageType.entries.forEach { + DropdownMenuItem( + text = { + Text( + text = it.displayName, + ) }, - modifier = Modifier - .pointerHoverIcon( - icon = PointerIcon.Default, - overrideDescendants = true, - ), - ) { - OutlinedTextField( - value = messageTypeState.value.displayName, - onValueChange = {}, - modifier = Modifier - .fillMaxWidth() - .menuAnchor(), - label = { - Text( - text = "Тип", - ) - }, - readOnly = true, - leadingIcon = { - Icon( - painter = painterResource(messageTypeState.value.icon), - contentDescription = null, - ) - }, - trailingIcon = { - ExposedDropdownMenuDefaults.TrailingIcon( - expanded = dropdownMenuState.value, - ) - }, - isError = false, - singleLine = true, - ) - ExposedDropdownMenu( - expanded = dropdownMenuState.value, - onDismissRequest = { - dropdownMenuState.value = false - }, - ) { - MessageType.entries.forEach { - DropdownMenuItem( - text = { - Text( - text = it.displayName, - ) - }, - onClick = { - messageTypeState.value = it - dropdownMenuState.value = false - }, - leadingIcon = { - Icon( - painter = painterResource(it.icon), - contentDescription = null, - ) - }, - ) - } - } - } - - when { - messageTypeState.value != MessageType.DICE -> { - Spacer( - modifier = Modifier - .height(16.dp), + onClick = { + messageTypeState.value = it + dropdownMenuState.value = false + }, + leadingIcon = { + Icon( + painter = painterResource(it.icon), + contentDescription = null, ) - Text( - text = messageTypeState.value.displayName, - style = MaterialTheme.typography.titleMedium, - ) - Spacer( - modifier = Modifier - .height(8.dp), - ) - } - } - - when (messageTypeState.value) { - MessageType.TEXT -> { - val textState = remember { - mutableStateOf("") - } - OutlinedTextField( - value = textState.value, - onValueChange = { value -> - textState.value = value - }, - modifier = Modifier - .fillMaxWidth(), - label = { - Text( - text = "Текст сообщения", - ) - }, - isError = false, - maxLines = 6, - ) - } - MessageType.POLL -> { - val questionState = remember { - mutableStateOf("") - } - OutlinedTextField( - value = questionState.value, - onValueChange = { value -> - questionState.value = value - }, - modifier = Modifier - .fillMaxWidth(), - label = { - Text( - text = "Вопрос", - ) - }, - isError = false, - singleLine = true, - ) - Spacer( - modifier = Modifier - .height(16.dp), - ) - Text( - text = "Варианты ответа", - style = MaterialTheme.typography.titleMedium, - ) - Spacer( - modifier = Modifier - .height(8.dp), - ) - val optionState = remember { - mutableStateOf("") - } - Row( - verticalAlignment = Alignment.CenterVertically, - ) { - OutlinedTextField( - value = optionState.value, - onValueChange = { value -> - optionState.value = value - }, - modifier = Modifier - .weight(1f), - label = {}, - isError = false, - singleLine = true, - ) - Spacer( - modifier = Modifier - .width(8.dp), - ) - IconButton( - onClick = {}, - ) { - Icon( - painter = painterResource(Res.drawable.outline_adjust_24), - contentDescription = null, - ) - } - } - Spacer( - modifier = Modifier - .height(16.dp), - ) - Text( - text = "Настройки", - style = MaterialTheme.typography.titleMedium, - ) - Spacer( - modifier = Modifier - .height(8.dp), - ) - val anonymousPollCheckboxState = remember { - mutableStateOf(false) - } - TextCheckbox( - text = "Анонимное голосование", - checkboxState = anonymousPollCheckboxState, - ) - val multiselectPollCheckboxState = remember { - mutableStateOf(false) - } - TextCheckbox( - text = "Выбор нескольких ответов", - checkboxState = multiselectPollCheckboxState, - ) - } - MessageType.MEDIA -> { - OutlinedButton( - onClick = {}, - ) { - Icon( - painter = painterResource(Res.drawable.baseline_attach_file_24), - contentDescription = null, - ) - Text( - text = "Прикрепить файл", - ) - } - } - MessageType.CONTACT -> { - val contactPhoneNumberState = remember { - mutableStateOf("") - } - OutlinedTextField( - value = contactPhoneNumberState.value, - onValueChange = { value -> - contactPhoneNumberState.value = value - }, - modifier = Modifier - .fillMaxWidth(), - label = { - Text( - text = "Номер телефона", - ) - }, - isError = false, - singleLine = true, - ) - Spacer( - modifier = Modifier - .height(8.dp), - ) - val contactNameState = remember { - mutableStateOf("") - } - OutlinedTextField( - value = contactNameState.value, - onValueChange = { value -> - contactNameState.value = value - }, - modifier = Modifier - .fillMaxWidth(), - label = { - Text( - text = "Имя", - ) - }, - isError = false, - singleLine = true, - ) - } - MessageType.DICE -> {} - } + }, + ) } } } + + when { + messageTypeState.value != MessageType.DICE -> { + Spacer( + modifier = Modifier + .height(16.dp), + ) + Text( + text = messageTypeState.value.displayName, + style = MaterialTheme.typography.titleMedium, + ) + Spacer( + modifier = Modifier + .height(8.dp), + ) + } + } + + when (messageTypeState.value) { + MessageType.TEXT -> { + val textState = remember { + mutableStateOf("") + } + OutlinedTextField( + value = textState.value, + onValueChange = { value -> + textState.value = value + }, + modifier = Modifier + .fillMaxWidth(), + label = { + Text( + text = "Текст сообщения", + ) + }, + isError = false, + maxLines = 6, + ) + } + MessageType.POLL -> { + val questionState = remember { + mutableStateOf("") + } + OutlinedTextField( + value = questionState.value, + onValueChange = { value -> + questionState.value = value + }, + modifier = Modifier + .fillMaxWidth(), + label = { + Text( + text = "Вопрос", + ) + }, + isError = false, + singleLine = true, + ) + Spacer( + modifier = Modifier + .height(16.dp), + ) + Text( + text = "Варианты ответа", + style = MaterialTheme.typography.titleMedium, + ) + Spacer( + modifier = Modifier + .height(8.dp), + ) + val optionState = remember { + mutableStateOf("") + } + Row( + verticalAlignment = Alignment.CenterVertically, + ) { + OutlinedTextField( + value = optionState.value, + onValueChange = { value -> + optionState.value = value + }, + modifier = Modifier + .weight(1f), + label = {}, + isError = false, + singleLine = true, + ) + Spacer( + modifier = Modifier + .width(8.dp), + ) + IconButton( + onClick = {}, + ) { + Icon( + painter = painterResource(Res.drawable.outline_adjust_24), + contentDescription = null, + ) + } + } + Spacer( + modifier = Modifier + .height(16.dp), + ) + Text( + text = "Настройки", + style = MaterialTheme.typography.titleMedium, + ) + Spacer( + modifier = Modifier + .height(8.dp), + ) + val anonymousPollCheckboxState = remember { + mutableStateOf(false) + } + TextCheckbox( + text = "Анонимное голосование", + checkboxState = anonymousPollCheckboxState, + ) + val multiselectPollCheckboxState = remember { + mutableStateOf(false) + } + TextCheckbox( + text = "Выбор нескольких ответов", + checkboxState = multiselectPollCheckboxState, + ) + } + MessageType.MEDIA -> { + OutlinedButton( + onClick = {}, + ) { + Icon( + painter = painterResource(Res.drawable.baseline_attach_file_24), + contentDescription = null, + ) + Text( + text = "Прикрепить файл", + ) + } + } + MessageType.CONTACT -> { + val contactPhoneNumberState = remember { + mutableStateOf("") + } + OutlinedTextField( + value = contactPhoneNumberState.value, + onValueChange = { value -> + contactPhoneNumberState.value = value + }, + modifier = Modifier + .fillMaxWidth(), + label = { + Text( + text = "Номер телефона", + ) + }, + isError = false, + singleLine = true, + ) + Spacer( + modifier = Modifier + .height(8.dp), + ) + val contactNameState = remember { + mutableStateOf("") + } + OutlinedTextField( + value = contactNameState.value, + onValueChange = { value -> + contactNameState.value = value + }, + modifier = Modifier + .fillMaxWidth(), + label = { + Text( + text = "Имя", + ) + }, + isError = false, + singleLine = true, + ) + } + MessageType.DICE -> {} + } } } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/ui/screens/ScenariosScreen.kt b/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/ui/screens/ScenariosScreen.kt index 9ad2b8c..85d5ad5 100644 --- a/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/ui/screens/ScenariosScreen.kt +++ b/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/ui/screens/ScenariosScreen.kt @@ -43,12 +43,31 @@ import org.jetbrains.compose.resources.painterResource import ru.csasq.cit_is_bot.ui.components.SwitchButton import ru.csasq.cit_is_bot.ui.dialogs.ScenarioDialog +@Serializable +enum class UserRole( + val displayName: String, +) { + User("Пользователь"), + Moderator("Модератор"), + Admin("Администратор"), +} + +@Serializable +data class User( + val id: Int, + val firstName: String, + val lastName: String?, + val username: String?, + val role: UserRole, +) + @Serializable data class Scenario( val id: Int? = null, + val owner: User, var name: String, - var time: String, - var messageNumber: String, + var startTime: String, + var messages: List, var isEnabled: Boolean, ) @@ -160,8 +179,15 @@ fun ScenariosScreen( onClick = { scenarioDialogState.value = Scenario( name = "", - time = "", - messageNumber = "", + owner = User( + id = 1, + firstName = "Глеб", + lastName = "Иваницкий", + username = "csasq", + role = UserRole.Admin, + ), + startTime = "", + messages = listOf(), isEnabled = true, ) }, @@ -174,9 +200,9 @@ fun ScenariosScreen( mutableStateOf(it.isEnabled) } val captionAnnotatedString = buildAnnotatedString { - append(it.time) + append(it.startTime) append(" \u2022 ") - append(it.messageNumber) + append(it.messages.size.toString()) } SwitchButton( title = it.name,