Skip to content

Commit

Permalink
Add possibility to share Composables with Web (#430)
Browse files Browse the repository at this point in the history
Co-authored-by: hfhbd <[email protected]>
  • Loading branch information
hfhbd and hfhbd committed Dec 23, 2021
1 parent 14d6382 commit 2773574
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class TodoViewModel(private val scope: CoroutineScope, private val repo: TodoRep
fun create(title: String, until: Instant?) {
scope.launch(Dispatchers.Default) {
repo.create(title = title, until = until)
repo.sync()
}
}

Expand Down
3 changes: 1 addition & 2 deletions web/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ kotlin {
sourceSets {
commonMain {
dependencies {
api(projects.clients) // try composeClients
api(projects.composeClients)
}
}
commonTest {
Expand All @@ -29,7 +29,6 @@ kotlin {

val jsMain by getting {
dependencies {
implementation("app.softwork:bootstrap-compose:0.0.49")
implementation("app.softwork:routing-compose:0.1.5")
implementation(compose.web.core)
implementation(compose.runtime)
Expand Down
6 changes: 4 additions & 2 deletions web/src/jsMain/kotlin/app/softwork/composetodo/login/Login.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package app.softwork.composetodo.login
import androidx.compose.runtime.*
import app.softwork.bootstrapcompose.*
import app.softwork.composetodo.*
import app.softwork.composetodo.Column
import app.softwork.composetodo.Row
import app.softwork.composetodo.Text
import app.softwork.composetodo.viewmodels.*
import kotlinx.coroutines.*
import org.jetbrains.compose.web.attributes.*
import org.jetbrains.compose.web.dom.*

Expand Down Expand Up @@ -37,7 +39,7 @@ fun Login(viewModel: LoginViewModel) {
}
val enableLogin by viewModel.enableLogin.collectAsState(false)

Button("Login $username", disabled = !enableLogin) {
Button("Login $username", enabled = enableLogin) {
viewModel.login()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package app.softwork.composetodo.login
import androidx.compose.runtime.*
import app.softwork.bootstrapcompose.*
import app.softwork.composetodo.*
import app.softwork.composetodo.dto.*
import app.softwork.composetodo.Column
import app.softwork.composetodo.Row
import app.softwork.composetodo.Text
import app.softwork.composetodo.viewmodels.*
import kotlinx.coroutines.*
import org.jetbrains.compose.web.attributes.*
import org.jetbrains.compose.web.dom.*

Expand Down Expand Up @@ -62,7 +63,7 @@ fun Register(viewModel: RegisterViewModel) {

val enableRegisterButton by viewModel.enableRegisterButton.collectAsState(false)

Button("Register", disabled = !enableRegisterButton) {
Button("Register", enabled = enableRegisterButton) {
viewModel.register()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.runtime.*
import app.softwork.composetodo.*
import app.softwork.composetodo.dto.Todo
import kotlinx.uuid.*
import org.jetbrains.compose.web.dom.*

@Composable
fun Todo(api: API.LoggedIn, todoID: UUID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fun Todos(viewModel: TodoViewModel) {
if (todos.isEmpty()) {
Text("No Todos created")
} else {
Table(data = todos, key = { it.id }) { _, todo ->
Table(data = todos.sortedBy { it.title }, key = { it.id }) { _, todo ->
rowColor = when {
todo.finished -> Color.Success
todo.until?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app.softwork.composetodo.users

import androidx.compose.runtime.*
import app.softwork.composetodo.*
import org.jetbrains.compose.web.dom.*

@Composable
fun Users(api: API.LoggedIn) {
Expand Down

0 comments on commit 2773574

Please sign in to comment.