feat: Add Sentiment and UI Changes (#14)
All checks were successful
Build / build (push) Successful in 5m3s
Release / release (push) Successful in 7m0s

-   Adds a `Sentiment` enum with friendly names and leading icons for `HAPPY`, `NEUTRAL`, and `SAD`.
-   Replaces the previous `Greeting` class with this new `Sentiment` based approach.
-   Updates the main UI (`App`) to use `FilterChip` for sentiment selection.
-   Adds a `TextField` for user comments and a "Submit" button.

Closes #1

Reviewed-on: #14
Co-authored-by: Ben Martin <ben.martin@sky.uk>
Co-committed-by: Ben Martin <ben.martin@sky.uk>
This commit is contained in:
Ben Martin 2025-01-21 12:50:47 +00:00 committed by Ben Martin
parent f74c22eea4
commit 54fdb64c40
3 changed files with 53 additions and 25 deletions

View file

@ -1,37 +1,67 @@
package uk.sky.bob.application package uk.sky.bob.application
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button import androidx.compose.material.Button
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.FilterChip
import androidx.compose.material.MaterialTheme import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.* import androidx.compose.material.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import org.jetbrains.compose.resources.painterResource import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp
import org.jetbrains.compose.ui.tooling.preview.Preview import org.jetbrains.compose.ui.tooling.preview.Preview
import bob.composeapp.generated.resources.Res @OptIn(ExperimentalMaterialApi::class)
import bob.composeapp.generated.resources.compose_multiplatform
@Composable @Composable
@Preview @Preview
fun App() { fun App() {
MaterialTheme { MaterialTheme {
var showContent by remember { mutableStateOf(false) }
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) { Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
Button(onClick = { showContent = !showContent }) { Row {
Text("Click me!") val state = remember { mutableStateOf(Sentiment.HAPPY) }
for (emotion in Sentiment.entries) {
FilterChip(
onClick = { state.value = emotion },
selected = state.value == emotion,
modifier = Modifier.padding(8.dp),
leadingIcon = { Text(emotion.leadingIcon) },
) {
Text(emotion.friendlyName)
} }
AnimatedVisibility(showContent) { }
val greeting = remember { Greeting().greet() } }
Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
Image(painterResource(Res.drawable.compose_multiplatform), null) Row {
Text("Compose: $greeting") var text by rememberSaveable(stateSaver = TextFieldValue.Saver) {
mutableStateOf(
TextFieldValue("")
)
}
TextField(
value = text,
onValueChange = { text = it },
label = { Text("Your comment") },
maxLines = 3,
)
}
Row {
Button(onClick = { /* Handle submit */ }) {
Text("Submit")
} }
} }
} }
} }
} }

View file

@ -1,9 +0,0 @@
package uk.sky.bob.application
class Greeting {
private val platform = getPlatform()
fun greet(): String {
return "Hello, ${platform.name}!"
}
}

View file

@ -0,0 +1,7 @@
package uk.sky.bob.application
enum class Sentiment(val friendlyName: String, val leadingIcon: String) {
HAPPY("Happy", "\uD83D\uDE03"),
NEUTRAL("Neutral", "\uD83D\uDE10"),
SAD("Sad", "\uD83D\uDE1E");
}