Skip to content

Commit d61ee81

Browse files
committed
Add KTO
1 parent e63afab commit d61ee81

File tree

6 files changed

+16
-76
lines changed

6 files changed

+16
-76
lines changed

build.gradle.kts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack
22

33
val serializationVersion = "1.6.2"
4-
val ktorVersion = "2.3.3"
4+
val ktorVersion = "3.0.0-wasm2"
55
val logbackVersion = "1.2.11"
66
val kotlinWrappersVersion = "1.0.0-pre.621"
77
val kmongoVersion = "4.5.0"
@@ -19,6 +19,7 @@ version = "1.0-SNAPSHOT"
1919
repositories {
2020
mavenCentral()
2121
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
22+
maven("https://maven.pkg.jetbrains.space/kotlin/p/wasm/experimental")
2223
}
2324

2425
kotlin {
@@ -38,6 +39,10 @@ kotlin {
3839
sourceSets {
3940
val commonMain by getting {
4041
dependencies {
42+
implementation(compose.runtime)
43+
implementation("io.ktor:ktor-client-core:$ktorVersion")
44+
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
45+
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
4146
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
4247
}
4348
}
@@ -51,7 +56,6 @@ kotlin {
5156

5257
val jvmMain by getting {
5358
dependencies {
54-
implementation("io.ktor:ktor-client-core:$ktorVersion")
5559
implementation("io.ktor:ktor-serialization:$ktorVersion")
5660
implementation("io.ktor:ktor-server-content-negotiation:$ktorVersion")
5761
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
@@ -66,10 +70,7 @@ kotlin {
6670

6771
val jsMain by getting {
6872
dependencies {
69-
implementation("io.ktor:ktor-client-core:$ktorVersion")
7073
implementation("io.ktor:ktor-client-js:$ktorVersion")
71-
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
72-
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
7374
implementation(project.dependencies.enforcedPlatform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:$kotlinWrappersVersion"))
7475
implementation("org.jetbrains.kotlin-wrappers:kotlin-react")
7576
implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom")
@@ -78,7 +79,6 @@ kotlin {
7879

7980
val wasmJsMain by getting {
8081
dependencies {
81-
implementation(compose.runtime)
8282
implementation(compose.ui)
8383
implementation(compose.foundation)
8484
implementation(compose.material3)
File renamed without changes.

src/wasmJsMain/kotlin/Api.kt

Whitespace-only changes.

src/wasmJsMain/kotlin/App.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ fun ShoppingList(viewModel: ShoppingListViewModel) {
3333
ShoppingListTheme {
3434
Surface {
3535
Column(Modifier.fillMaxSize()) {
36-
Input(onCreateItem = viewModel::addShoppingListItem)
36+
Input(onCreateItem = viewModel::pushShoppingListItem)
3737
LazyColumn {
3838
items(shoppingList.size) { index ->
3939
ShoppingItem(
4040
shoppingListItem = shoppingList[index],
41-
onDeleteClick = viewModel::deleteShoppingListItem
41+
onDeleteClick = viewModel::removeShoppingListItem
4242
)
4343
}
4444
}
@@ -66,12 +66,11 @@ fun Input(onCreateItem: (ShoppingListItem) -> Unit) = Column {
6666

6767
OutlinedTextField(
6868
value = input.value,
69+
singleLine = true,
6970
onValueChange = { input.value = it },
7071
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
7172
keyboardActions = KeyboardActions(onDone = { createShoppingItem() }),
72-
modifier = Modifier
73-
.weight(1f)
74-
.padding(8.dp),
73+
modifier = Modifier.weight(1f).padding(8.dp),
7574
)
7675
OutlinedButton(
7776
onClick = { createShoppingItem() },
@@ -88,7 +87,7 @@ fun ShoppingItem(shoppingListItem: ShoppingListItem, onDeleteClick: (ShoppingLis
8887
Row(
8988
modifier = Modifier
9089
.fillMaxWidth()
91-
.padding(8.dp),
90+
.padding(16.dp),
9291
verticalAlignment = Alignment.CenterVertically,
9392
) {
9493
Text("[${shoppingListItem.priority}] ${shoppingListItem.desc}", Modifier.weight(1f))

src/wasmJsMain/kotlin/HttpClient.kt

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/wasmJsMain/kotlin/ViewModel.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,25 @@ import kotlinx.coroutines.promise
77

88
@OptIn(DelicateCoroutinesApi::class)
99
class ShoppingListViewModel {
10-
private val jsonClient = HttpClient()
11-
1210
var shoppingList by mutableStateOf(listOf<ShoppingListItem>())
1311
private set
1412

1513
fun fetchShoppingList() {
1614
GlobalScope.promise {
17-
shoppingList = jsonClient.get(ShoppingListItem.path)
15+
shoppingList = getShoppingList()
1816
}
1917
}
2018

21-
fun addShoppingListItem(shoppingListItem: ShoppingListItem) {
19+
fun pushShoppingListItem(shoppingListItem: ShoppingListItem) {
2220
GlobalScope.promise {
23-
jsonClient.post(ShoppingListItem.path, shoppingListItem)
21+
addShoppingListItem(shoppingListItem)
2422
shoppingList += shoppingListItem
2523
}
2624
}
2725

28-
fun deleteShoppingListItem(shoppingListItem: ShoppingListItem) {
26+
fun removeShoppingListItem(shoppingListItem: ShoppingListItem) {
2927
GlobalScope.promise {
30-
jsonClient.delete(ShoppingListItem.path + "/${shoppingListItem.id}")
28+
deleteShoppingListItem(shoppingListItem)
3129
shoppingList -= shoppingListItem
3230
}
3331
}

0 commit comments

Comments
 (0)