Skip to content

Commit e4c122e

Browse files
committed
Add basic UI for the compose app with Wasm
1 parent 874ac28 commit e4c122e

File tree

9 files changed

+254
-55
lines changed

9 files changed

+254
-55
lines changed

build.gradle.kts

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

3-
val kotlinVersion = "1.9.10"
4-
val serializationVersion = "1.6.0"
3+
val serializationVersion = "1.6.2"
54
val ktorVersion = "2.3.3"
65
val logbackVersion = "1.2.11"
76
val kotlinWrappersVersion = "1.0.0-pre.621"
87
val kmongoVersion = "4.5.0"
98

109
plugins {
11-
kotlin("multiplatform") version "1.9.10"
10+
kotlin("multiplatform") version "1.9.21"
1211
application //to run JVM part
13-
kotlin("plugin.serialization") version "1.9.10"
12+
kotlin("plugin.serialization") version "1.9.21"
13+
id("org.jetbrains.compose") version "1.6.0-alpha01"
1414
}
1515

1616
group = "org.example"
1717
version = "1.0-SNAPSHOT"
1818

1919
repositories {
2020
mavenCentral()
21+
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
2122
}
2223

2324
kotlin {
@@ -29,11 +30,15 @@ kotlin {
2930
binaries.executable()
3031
}
3132
}
33+
wasmJs {
34+
browser {
35+
binaries.executable()
36+
}
37+
}
3238
sourceSets {
3339
val commonMain by getting {
3440
dependencies {
3541
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
36-
implementation("io.ktor:ktor-client-core:$ktorVersion")
3742
}
3843
}
3944

@@ -46,6 +51,7 @@ kotlin {
4651

4752
val jvmMain by getting {
4853
dependencies {
54+
implementation("io.ktor:ktor-client-core:$ktorVersion")
4955
implementation("io.ktor:ktor-serialization:$ktorVersion")
5056
implementation("io.ktor:ktor-server-content-negotiation:$ktorVersion")
5157
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
@@ -60,6 +66,7 @@ kotlin {
6066

6167
val jsMain by getting {
6268
dependencies {
69+
implementation("io.ktor:ktor-client-core:$ktorVersion")
6370
implementation("io.ktor:ktor-client-js:$ktorVersion")
6471
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
6572
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
@@ -68,13 +75,28 @@ kotlin {
6875
implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom")
6976
}
7077
}
78+
79+
val wasmJsMain by getting {
80+
dependencies {
81+
implementation(compose.runtime)
82+
implementation(compose.ui)
83+
implementation(compose.foundation)
84+
implementation(compose.material3)
85+
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
86+
implementation(compose.components.resources)
87+
}
88+
}
7189
}
7290
}
7391

7492
application {
7593
mainClass.set("ServerKt")
7694
}
7795

96+
compose.experimental {
97+
web.application {}
98+
}
99+
78100
// include JS artifacts in any JAR we generate
79101
tasks.named<Jar>("jvmJar").configure {
80102
val taskName = if (project.hasProperty("isProduction")
@@ -86,8 +108,9 @@ tasks.named<Jar>("jvmJar").configure {
86108
}
87109
val webpackTask = tasks.named<KotlinWebpack>(taskName)
88110
dependsOn(webpackTask)
89-
from(webpackTask.map { it.mainOutputFile.get().asFile }) // bring output file along into the JAR
111+
from(webpackTask.map { it.outputDirectory }) // bring output file along into the JAR
90112
into("static")
113+
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
91114
}
92115

93116
tasks {
@@ -116,4 +139,4 @@ tasks.register("stage") {
116139

117140
tasks.named<JavaExec>("run").configure {
118141
classpath(tasks.named<Jar>("jvmJar")) // so that the JS artifacts generated by `jvmJar` can be found and served
119-
}
142+
}

gradle.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ kotlin.js.compiler=ir
33
kotlin.incremental=true
44
kotlin.incremental.js=true
55
kotlin.incremental.js.ir=true
6-
kotlin.incremental.js.klib=true
6+
kotlin.incremental.js.klib=true
7+
org.jetbrains.compose.experimental.wasm.enabled=true
8+
kotlin.daemon.jvmargs=-Xmx4G

kotlin-js-store/yarn.lock

Lines changed: 62 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@
5454
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32"
5555
integrity sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==
5656

57-
"@jridgewell/trace-mapping@^0.3.17":
58-
version "0.3.19"
59-
resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.19.tgz#f8a3249862f91be48d3127c3cfe992f79b4b8811"
60-
integrity sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==
57+
"@jridgewell/trace-mapping@^0.3.20":
58+
version "0.3.20"
59+
resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.20.tgz#72e45707cf240fa6b081d0366f8265b0cd10197f"
60+
integrity sha512-R8LcPeWZol2zR8mmH3JeKQ6QRCFb7XgUhV9ZlGhHLGyg4wpPiPZNQOOWhFZhxKw8u//yTbNGI42Bx/3paXEQ+Q==
6161
dependencies:
6262
"@jridgewell/resolve-uri" "^3.1.0"
6363
"@jridgewell/sourcemap-codec" "^1.4.14"
@@ -70,6 +70,11 @@
7070
"@jridgewell/resolve-uri" "^3.0.3"
7171
"@jridgewell/sourcemap-codec" "^1.4.10"
7272

73+
"@js-joda/[email protected]":
74+
version "3.2.0"
75+
resolved "https://registry.yarnpkg.com/@js-joda/core/-/core-3.2.0.tgz#3e61e21b7b2b8a6be746df1335cf91d70db2a273"
76+
integrity sha512-PMqgJ0sw5B7FKb2d5bWYIoxjri+QlW/Pys7+Rw82jSH0QN3rB05jZ/VrrsUdh1w4+i2kw9JOejXGq/KhDOX7Kg==
77+
7378
"@leichtgewicht/ip-codec@^2.0.1":
7479
version "2.0.4"
7580
resolved "https://registry.yarnpkg.com/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz#b2ac626d6cb9c8718ab459166d4bb405b8ffa78b"
@@ -142,9 +147,9 @@
142147
integrity sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==
143148

144149
"@types/estree@^1.0.0":
145-
version "1.0.1"
146-
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.1.tgz#aa22750962f3bf0e79d753d3cc067f010c95f194"
147-
integrity sha512-LG4opVs2ANWZ1TJoKc937iMmNstM/d0ae1vNbnBvBhqCSezgVUOzcLCqbI5elV8Vy6WKwKjaqR+zO9VKirBBCA==
150+
version "1.0.5"
151+
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4"
152+
integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==
148153

149154
"@types/express-serve-static-core@*", "@types/express-serve-static-core@^4.17.18":
150155
version "4.17.30"
@@ -182,6 +187,13 @@
182187
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-3.0.1.tgz#5f8f2bca0a5863cb69bc0b0acd88c96cb1d4ae10"
183188
integrity sha512-Y4XFY5VJAuw0FgAqPNd6NNoV44jbq9Bz2L7Rh/J6jLTiHBSBJa9fxqQIvkIld4GsoDOcCbvzOUAbLPsSKKg+uA==
184189

190+
"@types/node-forge@^1.3.0":
191+
version "1.3.11"
192+
resolved "https://registry.yarnpkg.com/@types/node-forge/-/node-forge-1.3.11.tgz#0972ea538ddb0f4d9c2fa0ec5db5724773a604da"
193+
integrity sha512-FQx220y22OKNTqaByeBGqHWYz4cl94tpcxeFdvBo3wjG6XPBuZ0BNgNZRV5J5TFmmcsJ4IzsLkmGRiQbnYsBEQ==
194+
dependencies:
195+
"@types/node" "*"
196+
185197
"@types/node@*", "@types/node@>=10.0.0":
186198
version "18.6.5"
187199
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.6.5.tgz#06caea822caf9e59d5034b695186ee74154d2802"
@@ -929,9 +941,9 @@ envinfo@^7.7.3:
929941
integrity sha512-/o+BXHmB7ocbHEAs6F2EnG0ogybVVUdkRunTT2glZU9XAaGmhqskrvKwqXuDfNjEO0LZKWdejEEpnq8aM0tOaw==
930942

931943
es-module-lexer@^1.2.1:
932-
version "1.3.0"
933-
resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-1.3.0.tgz#6be9c9e0b4543a60cd166ff6f8b4e9dae0b0c16f"
934-
integrity sha512-vZK7T0N2CBmBOixhmjdqx2gWVbFZ4DXZ/NyRMZVlJXPa7CyFS+/a4QQsDGDQy9ZfEzxFuNEsMLeQJnKP2p5/JA==
944+
version "1.4.1"
945+
resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-1.4.1.tgz#41ea21b43908fe6a287ffcbe4300f790555331f5"
946+
integrity sha512-cXLGjP0c4T3flZJKQSuziYoq7MlT+rnvfZjfp7h+I7K9BNX54kP9nyWvdbwjQ4u1iWbOL4u96fgeZLToQlZC7w==
935947

936948
escalade@^3.1.1:
937949
version "3.1.1"
@@ -1180,6 +1192,11 @@ function-bind@^1.1.1:
11801192
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
11811193
integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==
11821194

1195+
function-bind@^1.1.2:
1196+
version "1.1.2"
1197+
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.2.tgz#2c02d864d97f3ea6c8830c464cbd11ab6eab7a1c"
1198+
integrity sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==
1199+
11831200
get-caller-file@^2.0.5:
11841201
version "2.0.5"
11851202
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e"
@@ -1267,6 +1284,13 @@ has@^1.0.3:
12671284
dependencies:
12681285
function-bind "^1.1.1"
12691286

1287+
hasown@^2.0.0:
1288+
version "2.0.0"
1289+
resolved "https://registry.yarnpkg.com/hasown/-/hasown-2.0.0.tgz#f4c513d454a57b7c7e1650778de226b11700546c"
1290+
integrity sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==
1291+
dependencies:
1292+
function-bind "^1.1.2"
1293+
12701294
12711295
version "1.2.0"
12721296
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
@@ -1406,11 +1430,11 @@ is-binary-path@~2.1.0:
14061430
binary-extensions "^2.0.0"
14071431

14081432
is-core-module@^2.13.0:
1409-
version "2.13.0"
1410-
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.13.0.tgz#bb52aa6e2cbd49a30c2ba68c42bf3435ba6072db"
1411-
integrity sha512-Z7dk6Qo8pOCp3l4tsX2C5ZVas4V+UxwQodwZhLopL91TX8UyyHEXafPcyoeeWuLrwzHcr3igO78wNLwHJHsMCQ==
1433+
version "2.13.1"
1434+
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.13.1.tgz#ad0d7532c6fea9da1ebdc82742d74525c6273384"
1435+
integrity sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==
14121436
dependencies:
1413-
has "^1.0.3"
1437+
hasown "^2.0.0"
14141438

14151439
is-docker@^2.0.0, is-docker@^2.1.1:
14161440
version "2.2.1"
@@ -1602,12 +1626,12 @@ kind-of@^6.0.2:
16021626
integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==
16031627

16041628
launch-editor@^2.6.0:
1605-
version "2.6.0"
1606-
resolved "https://registry.yarnpkg.com/launch-editor/-/launch-editor-2.6.0.tgz#4c0c1a6ac126c572bd9ff9a30da1d2cae66defd7"
1607-
integrity sha512-JpDCcQnyAAzZZaZ7vEiSqL690w7dAEyLao+KC96zBplnYbJS7TYNjvM3M7y3dGz+v7aIsJk3hllWuc0kWAjyRQ==
1629+
version "2.6.1"
1630+
resolved "https://registry.yarnpkg.com/launch-editor/-/launch-editor-2.6.1.tgz#f259c9ef95cbc9425620bbbd14b468fcdb4ffe3c"
1631+
integrity sha512-eB/uXmFVpY4zezmGp5XtU21kwo7GBbKB+EQ+UZeWtGb9yAM5xt/Evk+lYH3eRNAtId+ej4u7TYPFZ07w4s7rRw==
16081632
dependencies:
16091633
picocolors "^1.0.0"
1610-
shell-quote "^1.7.3"
1634+
shell-quote "^1.8.1"
16111635

16121636
loader-runner@^4.2.0:
16131637
version "4.3.0"
@@ -2122,9 +2146,9 @@ resolve-from@^5.0.0:
21222146
integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==
21232147

21242148
resolve@^1.20.0:
2125-
version "1.22.4"
2126-
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.4.tgz#1dc40df46554cdaf8948a486a10f6ba1e2026c34"
2127-
integrity sha512-PXNdCiPqDqeUou+w1C2eTQbNfxKSuMxqTCuvlmmMsk1NWHL5fRrhY6Pl0qEYYc6+QqGClco1Qj8XnjPego4wfg==
2149+
version "1.22.8"
2150+
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.8.tgz#b6c87a9f2aa06dfab52e3d70ac8cde321fa5a48d"
2151+
integrity sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==
21282152
dependencies:
21292153
is-core-module "^2.13.0"
21302154
path-parse "^1.0.7"
@@ -2203,10 +2227,11 @@ select-hose@^2.0.0:
22032227
integrity sha512-mEugaLK+YfkijB4fx0e6kImuJdCIt2LxCRcbEYPqRGCs4F2ogyfZU5IAZRdjCP8JPq2AtdNoC/Dux63d9Kiryg==
22042228

22052229
selfsigned@^2.1.1:
2206-
version "2.1.1"
2207-
resolved "https://registry.yarnpkg.com/selfsigned/-/selfsigned-2.1.1.tgz#18a7613d714c0cd3385c48af0075abf3f266af61"
2208-
integrity sha512-GSL3aowiF7wa/WtSFwnUrludWFoNhftq8bUkH9pkzjpN2XSPOAYEgg6e0sS9s0rZwgJzJiQRPU18A6clnoW5wQ==
2230+
version "2.4.1"
2231+
resolved "https://registry.yarnpkg.com/selfsigned/-/selfsigned-2.4.1.tgz#560d90565442a3ed35b674034cec4e95dceb4ae0"
2232+
integrity sha512-th5B4L2U+eGLq1TVh7zNRGBapioSORUeymIydxgFpwww9d2qyKvtuPU2jJuHvYAwwqi2Y596QBL3eEqcPEYL8Q==
22092233
dependencies:
2234+
"@types/node-forge" "^1.3.0"
22102235
node-forge "^1"
22112236

22122237
@@ -2294,7 +2319,7 @@ shebang-regex@^3.0.0:
22942319
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
22952320
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
22962321

2297-
shell-quote@^1.7.3:
2322+
shell-quote@^1.8.1:
22982323
version "1.8.1"
22992324
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.8.1.tgz#6dbf4db75515ad5bac63b4f1894c3a154c766680"
23002325
integrity sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==
@@ -2482,20 +2507,20 @@ tapable@^2.1.1, tapable@^2.2.0:
24822507
integrity sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ==
24832508

24842509
terser-webpack-plugin@^5.3.7:
2485-
version "5.3.9"
2486-
resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.9.tgz#832536999c51b46d468067f9e37662a3b96adfe1"
2487-
integrity sha512-ZuXsqE07EcggTWQjXUj+Aot/OMcD0bMKGgF63f7UxYcu5/AJF53aIpK1YoP5xR9l6s/Hy2b+t1AM0bLNPRuhwA==
2510+
version "5.3.10"
2511+
resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-5.3.10.tgz#904f4c9193c6fd2a03f693a2150c62a92f40d199"
2512+
integrity sha512-BKFPWlPDndPs+NGGCr1U59t0XScL5317Y0UReNrHaw9/FwhPENlq6bfgs+4yPfyP51vqC1bQ4rp1EfXW5ZSH9w==
24882513
dependencies:
2489-
"@jridgewell/trace-mapping" "^0.3.17"
2514+
"@jridgewell/trace-mapping" "^0.3.20"
24902515
jest-worker "^27.4.5"
24912516
schema-utils "^3.1.1"
24922517
serialize-javascript "^6.0.1"
2493-
terser "^5.16.8"
2518+
terser "^5.26.0"
24942519

2495-
terser@^5.16.8:
2496-
version "5.19.3"
2497-
resolved "https://registry.yarnpkg.com/terser/-/terser-5.19.3.tgz#359baeba615aef13db4b8c4d77a2aa0d8814aa9e"
2498-
integrity sha512-pQzJ9UJzM0IgmT4FAtYI6+VqFf0lj/to58AV0Xfgg0Up37RyPG7Al+1cepC6/BVuAxR9oNb41/DL4DEoHJvTdg==
2520+
terser@^5.26.0:
2521+
version "5.26.0"
2522+
resolved "https://registry.yarnpkg.com/terser/-/terser-5.26.0.tgz#ee9f05d929f4189a9c28a0feb889d96d50126fe1"
2523+
integrity sha512-dytTGoE2oHgbNV9nTzgBEPaqAWvcJNl66VZ0BkJqlvp71IjO8CxdBx/ykCNb47cLnCmCvRZ6ZR0tLkqvZCdVBQ==
24992524
dependencies:
25002525
"@jridgewell/source-map" "^0.3.3"
25012526
acorn "^8.8.2"
@@ -2801,9 +2826,9 @@ [email protected]:
28012826
integrity sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==
28022827

28032828
ws@^8.13.0:
2804-
version "8.13.0"
2805-
resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0"
2806-
integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==
2829+
version "8.16.0"
2830+
resolved "https://registry.yarnpkg.com/ws/-/ws-8.16.0.tgz#d1cd774f36fbc07165066a60e40323eab6446fd4"
2831+
integrity sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==
28072832

28082833
ws@~8.2.3:
28092834
version "8.2.3"

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
pluginManagement {
22
repositories {
3+
google()
34
mavenCentral()
45
gradlePluginPortal()
6+
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
57
}
68
}
79
rootProject.name = "shoppinglist"

src/commonMain/resources/static/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
</head>
77
<body>
88
<div id="root"></div>
9-
<script src="shoppinglist.js"></script>
9+
<canvas id="ComposeTarget"></canvas>
10+
<script type="application/javascript" src="skiko.js"></script>
11+
<script type="application/javascript" src="shoppinglist.js"></script>
1012
</body>
1113
</html>

src/jvmMain/kotlin/Server.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ import io.ktor.serialization.kotlinx.json.*
1515
import io.ktor.server.plugins.cors.routing.*
1616
import org.litote.kmongo.reactivestreams.KMongo
1717

18-
val connectionString: ConnectionString? = System.getenv("MONGODB_URI")?.let {
19-
ConnectionString("$it?retryWrites=false")
20-
}
18+
//val connectionString: ConnectionString? = System.getenv("MONGODB_URI")?.let {
19+
// ConnectionString("$it?retryWrites=false")
20+
//}
21+
22+
//val client = if (connectionString != null) KMongo.createClient(connectionString).coroutine else KMongo.createClient().coroutine
23+
//val database = client.getDatabase(connectionString?.database ?: "shoppingList")
24+
//val collection = database.getCollection<ShoppingListItem>()
2125

22-
val client = if (connectionString != null) KMongo.createClient(connectionString).coroutine else KMongo.createClient().coroutine
23-
val database = client.getDatabase(connectionString?.database ?: "shoppingList")
24-
val collection = database.getCollection<ShoppingListItem>()
26+
val collection = mutableListOf<ShoppingListItem>();
2527

2628
fun main() {
2729
val port = System.getenv("PORT")?.toInt() ?: 9090
@@ -44,15 +46,15 @@ fun main() {
4446
staticResources("/", "static")
4547
route(ShoppingListItem.path) {
4648
get {
47-
call.respond(collection.find().toList())
49+
call.respond(collection)
4850
}
4951
post {
50-
collection.insertOne(call.receive<ShoppingListItem>())
52+
collection.add(call.receive<ShoppingListItem>())
5153
call.respond(HttpStatusCode.OK)
5254
}
5355
delete("/{id}") {
5456
val id = call.parameters["id"]?.toInt() ?: error("Invalid delete request")
55-
collection.deleteOne(ShoppingListItem::id eq id)
57+
collection.removeIf { it.id == id }
5658
call.respond(HttpStatusCode.OK)
5759
}
5860
}

0 commit comments

Comments
 (0)