diff --git a/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/App.kt b/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/App.kt index eeda90a..e58d410 100644 --- a/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/App.kt +++ b/composeApp/src/commonMain/kotlin/ru/csasq/cit_is_bot/App.kt @@ -48,7 +48,7 @@ sealed class Screen( title = "Дашборд", icon = Res.drawable.baseline_dashboard_24, ) - data object Messages : Screen( + data object Scenarios : Screen( route = "scenarios", title = "Сценарии", icon = Res.drawable.baseline_edit_calendar_24, @@ -75,12 +75,18 @@ fun App() { val snackbarHostState = remember { SnackbarHostState() } - val scheduleFloatingActionButtonVisibleState = remember { + val floatingActionButtonVisibleState = remember { mutableStateOf(false) } + val floatingActionButtonOnClickState = remember { + mutableStateOf<(() -> Unit)?>(null) + } val createRuleDialogOpeningState = remember { mutableStateOf(false) } + val floatingActionButtonExpandedState = remember { + mutableStateOf(true) + } Scaffold( topBar = { TopAppBar( @@ -96,7 +102,7 @@ fun App() { val navBackStackEntry = navController.currentBackStackEntryAsState() val items = listOf( Screen.Dashboard, - Screen.Messages, + Screen.Scenarios, Screen.Chats, Screen.Users, ) @@ -138,7 +144,7 @@ fun App() { }, floatingActionButton = { AnimatedVisibility( - visible = scheduleFloatingActionButtonVisibleState.value, + visible = floatingActionButtonVisibleState.value, enter = fadeIn() + expandHorizontally(), exit = fadeOut() + shrinkHorizontally() ) { @@ -154,10 +160,8 @@ fun App() { contentDescription = null, ) }, - onClick = { - createRuleDialogOpeningState.value = true - }, - expanded = true, + onClick = floatingActionButtonOnClickState.value ?: {}, + expanded = floatingActionButtonExpandedState.value, ) } }, @@ -167,27 +171,24 @@ fun App() { startDestination = Screen.Dashboard.route, ) { composable(Screen.Dashboard.route) { - scheduleFloatingActionButtonVisibleState.value = false + floatingActionButtonVisibleState.value = false DashboardScreen(navController, paddingValues) } - composable(Screen.Messages.route) { - ScenariosScreen(navController, paddingValues) - scheduleFloatingActionButtonVisibleState.value = true - -// when { -// createRuleDialogOpeningState.value -> CallProtectionRuleDialog( -// database = database, -// scheduleRule = null, -// state = createRuleDialogOpeningState, -// ) -// } + composable(Screen.Scenarios.route) { + floatingActionButtonVisibleState.value = true + ScenariosScreen( + navController, + paddingValues, + floatingActionButtonOnClickState, + floatingActionButtonExpandedState, + ) } composable(Screen.Chats.route) { - scheduleFloatingActionButtonVisibleState.value = false + floatingActionButtonVisibleState.value = false ChatsScreen(navController, paddingValues) } composable(Screen.Users.route) { - scheduleFloatingActionButtonVisibleState.value = false + floatingActionButtonVisibleState.value = false UsersScreen(navController, paddingValues) } } 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 3fe6621..f050180 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 @@ -51,7 +51,7 @@ fun ScenarioDialog( TopAppBar( title = { Text( - text = scenarioDialogState.value?.let { + text = scenarioDialogState.value?.id?.let { "Изменить сценарий" } ?: "Добавить сценарий", overflow = TextOverflow.Ellipsis, 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 21c7476..482196c 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 @@ -1,24 +1,28 @@ package ru.csasq.cit_is_bot.ui.screens +import androidx.compose.foundation.ScrollState import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.MutableState import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Modifier +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.input.nestedscroll.NestedScrollConnection +import androidx.compose.ui.input.nestedscroll.NestedScrollSource +import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.text.buildAnnotatedString -import androidx.compose.ui.unit.dp import androidx.navigation.NavController import ru.csasq.cit_is_bot.ui.components.SwitchButton import ru.csasq.cit_is_bot.ui.dialogs.ScenarioDialog data class Scenario( - val id: Int, + val id: Int? = null, val name: String, val daysOfWeek: String, val time: String, @@ -35,6 +39,8 @@ val scenarioList = listOf( fun ScenariosScreen( navController: NavController, paddingValues: PaddingValues, + floatingActionButtonOnClickState: MutableState<(() -> Unit)?>, + floatingActionButtonExpandedState: MutableState, ) { Column( modifier = Modifier @@ -49,6 +55,15 @@ fun ScenariosScreen( val scenarioDialogState = remember { mutableStateOf(null) } + floatingActionButtonOnClickState.value = { + scenarioDialogState.value = Scenario( + name = "", + daysOfWeek = "", + time = "", + messageNumber = "", + isEnabled = true, + ) + } scenarioList.forEach { val scenarioSwitchState = remember { mutableStateOf(it.isEnabled)