Skip to content

Commit ff679b3

Browse files
committed
fix: styling fix and review
1 parent 3b697c7 commit ff679b3

File tree

6 files changed

+29
-34
lines changed

6 files changed

+29
-34
lines changed

alchemist-composeui/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ kotlin {
3131
sourceSets {
3232
val commonMain by getting {
3333
dependencies {
34+
api(alchemist("graphql"))
3435
implementation(compose.runtime)
3536
implementation(compose.ui)
3637
implementation(compose.foundation)
@@ -39,7 +40,6 @@ kotlin {
3940
implementation(libs.androidx.lifecycle.runtime.compose)
4041
implementation(libs.androidx.lifecycle.viewmodel.compose)
4142
implementation(libs.apollo.runtime)
42-
api(alchemist("graphql"))
4343
}
4444
}
4545

alchemist-composeui/src/commonMain/kotlin/it/unibo/alchemist/boundary/composeui/App.kt

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ import it.unibo.alchemist.boundary.composeui.viewmodels.SimulationViewModel
4141
* Application entry point, this will be rendered the same in all the platforms.
4242
*/
4343
@Composable
44-
fun app(viewModel: SimulationViewModel = viewModel { SimulationViewModel() }) {
44+
fun App(viewModel: SimulationViewModel = viewModel { SimulationViewModel() }) {
4545
val status by viewModel.status.collectAsStateWithLifecycle()
4646
val errors by viewModel.errors.collectAsStateWithLifecycle()
4747
val nodes by viewModel.nodes.collectAsStateWithLifecycle()
4848
Scaffold(
49-
topBar = { topBar(status) },
49+
topBar = { TopBar(status) },
5050
) { innerPadding ->
5151
Column(
5252
modifier = Modifier.padding(innerPadding).padding(horizontal = 8.dp, vertical = 16.dp),
5353
verticalArrangement = Arrangement.spacedBy(16.dp),
5454
) {
55-
controlButton(status, viewModel::play, viewModel::pause)
55+
ControlButton(status, viewModel::play, viewModel::pause)
5656
OutlinedCard(
5757
modifier = Modifier.fillMaxSize(),
5858
colors = CardDefaults.cardColors(
@@ -66,9 +66,11 @@ fun app(viewModel: SimulationViewModel = viewModel { SimulationViewModel() }) {
6666
rememberScrollState(),
6767
),
6868
) {
69-
errorDialog(viewModel::fetch, errors)
69+
if (errors.isNotEmpty()) {
70+
ErrorDialog(viewModel::fetch, errors)
71+
}
7072
for (node in nodes) {
71-
nodeDrawer(node.id)
73+
NodeDrawer(node.id)
7274
}
7375
}
7476
}
@@ -81,7 +83,7 @@ fun app(viewModel: SimulationViewModel = viewModel { SimulationViewModel() }) {
8183
*/
8284
@OptIn(ExperimentalMaterial3Api::class)
8385
@Composable
84-
fun topBar(status: SimulationStatus) {
86+
fun TopBar(status: SimulationStatus) {
8587
TopAppBar(
8688
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
8789
containerColor = MaterialTheme.colorScheme.primaryContainer,
@@ -99,7 +101,7 @@ fun topBar(status: SimulationStatus) {
99101
* Button to control the simulation.
100102
*/
101103
@Composable
102-
fun controlButton(status: SimulationStatus, resume: () -> Unit, pause: () -> Unit) {
104+
fun ControlButton(status: SimulationStatus, resume: () -> Unit, pause: () -> Unit) {
103105
if (status == SimulationStatus.Running) {
104106
Button(onClick = { pause() }) {
105107
Text("Pause", modifier = Modifier.padding(8.dp))
@@ -115,21 +117,19 @@ fun controlButton(status: SimulationStatus, resume: () -> Unit, pause: () -> Uni
115117
* Display the error dialog, currently used to circumvent the null issue we're facing when subscribing to simulation.
116118
*/
117119
@Composable
118-
fun errorDialog(dismiss: () -> Unit, errors: List<Error>?) {
119-
if (!errors.isNullOrEmpty()) {
120-
AlertDialog(
121-
onDismissRequest = dismiss,
122-
title = { Text("Error") },
123-
text = {
124-
for (error in errors) {
125-
Text(error.message)
126-
}
127-
},
128-
confirmButton = {
129-
Button(onClick = dismiss) {
130-
Text("OK")
131-
}
132-
},
133-
)
134-
}
120+
fun ErrorDialog(dismiss: () -> Unit, errors: List<Error>) {
121+
AlertDialog(
122+
onDismissRequest = dismiss,
123+
title = { Text("Error") },
124+
text = {
125+
for (error in errors) {
126+
Text(error.message)
127+
}
128+
},
129+
confirmButton = {
130+
Button(onClick = dismiss) {
131+
Text("OK")
132+
}
133+
},
134+
)
135135
}

alchemist-composeui/src/commonMain/kotlin/it/unibo/alchemist/boundary/composeui/NodeDrawer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import it.unibo.alchemist.boundary.composeui.viewmodels.NodeViewModel
2020
* Display the information of a node, subscribing to its own channel for data.
2121
*/
2222
@Composable
23-
fun nodeDrawer(nodeId: Int) {
23+
fun NodeDrawer(nodeId: Int) {
2424
val nodeModel: NodeViewModel = viewModel(key = "node-$nodeId") { NodeViewModel(nodeId) }
2525
val nodeInfo by nodeModel.nodeInfo.collectAsStateWithLifecycle()
2626
Text("Node $nodeId: $nodeInfo")

alchemist-composeui/src/jsMain/kotlin/it/unibo/alchemist/boundary/composeui/Main.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import org.jetbrains.skiko.wasm.onWasmReady
2121
fun main() {
2222
onWasmReady {
2323
ComposeViewport(checkNotNull(document.body)) {
24-
app()
24+
App()
2525
}
2626
}
2727
}

alchemist-composeui/src/jvmMain/kotlin/it/unibo/alchemist/boundary/composeui/ComposeMonitor.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,7 @@ class ComposeMonitor : OutputMonitor<Any, Nothing> {
2929
runBlocking {
3030
launch {
3131
awaitApplication {
32-
Window(
33-
onCloseRequest = ::exitApplication,
34-
title = "Alchemist",
35-
) {
36-
app()
37-
}
32+
Window(onCloseRequest = ::exitApplication, title = "Alchemist") { App() }
3833
}
3934
}
4035
}

alchemist-composeui/src/wasmJsMain/kotlin/it/unibo/alchemist/boundary/composeui/Main.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ import kotlinx.browser.document
1919
@OptIn(ExperimentalComposeUiApi::class)
2020
fun main() {
2121
ComposeViewport(checkNotNull(document.body)) {
22-
app()
22+
App()
2323
}
2424
}

0 commit comments

Comments
 (0)