Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c1e5dea
Add solution including MongoDB
SebastianAigner Apr 16, 2020
566b657
Group ShoppingListItem routes by path
SebastianAigner Apr 16, 2020
00286de
Fix https://github.com/kotlin-hands-on/hands-on/issues/82
SebastianAigner Jun 29, 2020
b27964a
kotlin.browser => kotlinx.browser
SebastianAigner Aug 26, 2020
f8d5666
Update useEffect to use new, consistent API
SebastianAigner Jul 2, 2021
ef6c599
Update for wrappers pre.265
SebastianAigner Nov 11, 2021
299cc97
Change capitalization of "App"
SebastianAigner Nov 11, 2021
4ecbd06
Change capitalization of "InputComponent"
SebastianAigner Nov 11, 2021
db7eeaf
Use delegation
SebastianAigner Nov 11, 2021
3283b7f
Update to new Kotlin-React DSL
SebastianAigner Feb 15, 2022
fce5c5a
Adjust for Ktor 2.x APIs
SebastianAigner Aug 10, 2022
b4bebe1
Remove unnecessary window.location.origin usage.
NightlyNexus Oct 2, 2022
8aba666
Update Server.kt
pristalovpavel Mar 27, 2023
f96177b
update: js ir and version upgrade
danil-pavlov Jun 17, 2023
6fcd4c1
Gradle: use Configuration avoidance
CristianGM May 2, 2022
c28fdcc
Bumpt version to 1.9.10 with the relevant changes
JSMonk Aug 30, 2023
6b9788e
remove unused import
JSMonk Aug 30, 2023
874ac28
Remove unnecessary `get` handler
JSMonk Sep 4, 2023
e4c122e
Add basic UI for the compose app with Wasm
JSMonk Jan 5, 2024
e63afab
Add API emulation
JSMonk Jan 5, 2024
d61ee81
Add KTO
JSMonk Jan 5, 2024
27641ba
Use syntax sugar the state
JSMonk Jan 5, 2024
ce02939
Add gradle property to switch in between JS and WASM
JSMonk Jan 5, 2024
5cc51be
Uncomment server logic for MongoDB
JSMonk Jan 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add KTO
  • Loading branch information
JSMonk committed Jan 5, 2024
commit d61ee81a86d039fa4583de20178c044764cf6d80
12 changes: 6 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack

val serializationVersion = "1.6.2"
val ktorVersion = "2.3.3"
val ktorVersion = "3.0.0-wasm2"
val logbackVersion = "1.2.11"
val kotlinWrappersVersion = "1.0.0-pre.621"
val kmongoVersion = "4.5.0"
Expand All @@ -19,6 +19,7 @@ version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
maven("https://maven.pkg.jetbrains.space/kotlin/p/wasm/experimental")
}

kotlin {
Expand All @@ -38,6 +39,10 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(compose.runtime)
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:$serializationVersion")
}
}
Expand All @@ -51,7 +56,6 @@ kotlin {

val jvmMain by getting {
dependencies {
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-serialization:$ktorVersion")
implementation("io.ktor:ktor-server-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
Expand All @@ -66,10 +70,7 @@ kotlin {

val jsMain by getting {
dependencies {
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-js:$ktorVersion")
implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation(project.dependencies.enforcedPlatform("org.jetbrains.kotlin-wrappers:kotlin-wrappers-bom:$kotlinWrappersVersion"))
implementation("org.jetbrains.kotlin-wrappers:kotlin-react")
implementation("org.jetbrains.kotlin-wrappers:kotlin-react-dom")
Expand All @@ -78,7 +79,6 @@ kotlin {

val wasmJsMain by getting {
dependencies {
implementation(compose.runtime)
implementation(compose.ui)
implementation(compose.foundation)
implementation(compose.material3)
Expand Down
File renamed without changes.
Empty file removed src/wasmJsMain/kotlin/Api.kt
Empty file.
11 changes: 5 additions & 6 deletions src/wasmJsMain/kotlin/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ fun ShoppingList(viewModel: ShoppingListViewModel) {
ShoppingListTheme {
Surface {
Column(Modifier.fillMaxSize()) {
Input(onCreateItem = viewModel::addShoppingListItem)
Input(onCreateItem = viewModel::pushShoppingListItem)
LazyColumn {
items(shoppingList.size) { index ->
ShoppingItem(
shoppingListItem = shoppingList[index],
onDeleteClick = viewModel::deleteShoppingListItem
onDeleteClick = viewModel::removeShoppingListItem
)
}
}
Expand Down Expand Up @@ -66,12 +66,11 @@ fun Input(onCreateItem: (ShoppingListItem) -> Unit) = Column {

OutlinedTextField(
value = input.value,
singleLine = true,
onValueChange = { input.value = it },
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onDone = { createShoppingItem() }),
modifier = Modifier
.weight(1f)
.padding(8.dp),
modifier = Modifier.weight(1f).padding(8.dp),
)
OutlinedButton(
onClick = { createShoppingItem() },
Expand All @@ -88,7 +87,7 @@ fun ShoppingItem(shoppingListItem: ShoppingListItem, onDeleteClick: (ShoppingLis
Row(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp),
.padding(16.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Text("[${shoppingListItem.priority}] ${shoppingListItem.desc}", Modifier.weight(1f))
Expand Down
57 changes: 0 additions & 57 deletions src/wasmJsMain/kotlin/HttpClient.kt

This file was deleted.

12 changes: 5 additions & 7 deletions src/wasmJsMain/kotlin/ViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,25 @@ import kotlinx.coroutines.promise

@OptIn(DelicateCoroutinesApi::class)
class ShoppingListViewModel {
private val jsonClient = HttpClient()

var shoppingList by mutableStateOf(listOf<ShoppingListItem>())
private set

fun fetchShoppingList() {
GlobalScope.promise {
shoppingList = jsonClient.get(ShoppingListItem.path)
shoppingList = getShoppingList()
}
}

fun addShoppingListItem(shoppingListItem: ShoppingListItem) {
fun pushShoppingListItem(shoppingListItem: ShoppingListItem) {
GlobalScope.promise {
jsonClient.post(ShoppingListItem.path, shoppingListItem)
addShoppingListItem(shoppingListItem)
shoppingList += shoppingListItem
}
}

fun deleteShoppingListItem(shoppingListItem: ShoppingListItem) {
fun removeShoppingListItem(shoppingListItem: ShoppingListItem) {
GlobalScope.promise {
jsonClient.delete(ShoppingListItem.path + "/${shoppingListItem.id}")
deleteShoppingListItem(shoppingListItem)
shoppingList -= shoppingListItem
}
}
Expand Down