From 77ecc4dc5a57d18001f4bf9b70ce3c8c531417c2 Mon Sep 17 00:00:00 2001 From: Anthony Date: Wed, 1 May 2024 15:29:51 +0100 Subject: [PATCH] feat(connector): add TestRun screen --- .../kotlin/tab/test/TestContent.kt | 4 +- .../desktopMain/kotlin/tab/test/TestRun.kt | 66 +++++++++++++++++++ 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 connector/composeApp/src/desktopMain/kotlin/tab/test/TestRun.kt diff --git a/connector/composeApp/src/desktopMain/kotlin/tab/test/TestContent.kt b/connector/composeApp/src/desktopMain/kotlin/tab/test/TestContent.kt index 986a162..3d82f4b 100644 --- a/connector/composeApp/src/desktopMain/kotlin/tab/test/TestContent.kt +++ b/connector/composeApp/src/desktopMain/kotlin/tab/test/TestContent.kt @@ -14,9 +14,9 @@ class TestContent : Screen { val state by screenModel.state.collectAsState() when (val s = state) { - is ActionsState.Loading -> LoadingScreen("Simulator Test") + is ActionsState.Loading -> LoadingScreen("Simulator Test").Content() is ActionsState.Idle -> { /* TODO implement error? */ } - is ActionsState.Result -> TODO("Not yet implemented") + is ActionsState.Result -> TestRun(s.actions).Content() } LaunchedEffect(currentCompositeKeyHash) { diff --git a/connector/composeApp/src/desktopMain/kotlin/tab/test/TestRun.kt b/connector/composeApp/src/desktopMain/kotlin/tab/test/TestRun.kt new file mode 100644 index 0000000..1d64bf3 --- /dev/null +++ b/connector/composeApp/src/desktopMain/kotlin/tab/test/TestRun.kt @@ -0,0 +1,66 @@ +package tab.test + +import androidx.compose.foundation.VerticalScrollbar +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.foundation.rememberScrollbarAdapter +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.Info +import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.Icon +import androidx.compose.material3.ListItem +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import cafe.adriel.voyager.core.screen.Screen +import io.anthonyberg.connector.shared.entity.Action + +class TestRun ( + private val actions: List +) : Screen { + @Composable + override fun Content() { + val lazyState = rememberLazyListState(0) + + Column( + modifier = Modifier.fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally, + ) { + Box( + modifier = Modifier.fillMaxWidth(0.7F) + ) { + LazyColumn { + items(actions) { action -> + ActionItem(action) + } + } + + VerticalScrollbar( + modifier = Modifier + .align(Alignment.CenterEnd) + .fillMaxHeight(), + adapter = rememberScrollbarAdapter( + scrollState = lazyState, + ), + ) + } + } + } + + @Composable + private fun ActionItem(action: Action) { + ListItem( + headlineContent = { Text(action.type) }, + supportingContent = { Text("Goal: ${action.goal}") }, + leadingContent = { Icon(Icons.Outlined.Info, null) } + ) + + HorizontalDivider() + } +}