Skip to content
Snippets Groups Projects
Commit 6dc85af1 authored by Tóth Miklós Tibor's avatar Tóth Miklós Tibor :shrug:
Browse files

Implement auto-refresh

parent 5df0a257
Branches
No related tags found
No related merge requests found
......@@ -5,9 +5,7 @@ import io.ktor.client.engine.js.*
import io.ktor.client.features.json.*
import io.ktor.client.features.json.serializer.*
import io.ktor.client.request.*
import io.ktor.client.response.*
import kotlinx.browser.window
import kotlinx.coroutines.delay
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.serialization.ExperimentalSerializationApi
......@@ -15,14 +13,14 @@ import kotlinx.serialization.json.Json
object Api {
val client = HttpClient(Js) {
install(JsonFeature) { serializer = KotlinxSerializer() }
}
private val json = Json {
ignoreUnknownKeys = true
}
val client = HttpClient(Js) {
install(JsonFeature) { serializer = KotlinxSerializer(json) }
}
var lastRequestTime: Instant = Instant.DISTANT_PAST
private set
......
......@@ -5,6 +5,7 @@ import api.Api
import api.Machine
import api.Response
import app.softwork.bootstrapcompose.Container
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.jetbrains.compose.web.css.*
import org.jetbrains.compose.web.dom.Div
......@@ -17,7 +18,15 @@ fun content() {
val scope = rememberCoroutineScope()
LaunchedEffect(Unit) {
scope.launch { data = Api.getOnce() }
scope.launch {
data = Api.getOnce()
while (true) {
delay(5000)
data = Api.getOnce()
val nextMachine = data!!.floors.map{ it.machines }.flatten().find { it.id == machine?.id }
machine = nextMachine
}
}
}
Container(attrs = {
......@@ -44,7 +53,7 @@ fun content() {
style {
width(0.px)
if (machine != null) {
height(17.em)
height(22.em)
} else {
height(0.em)
}
......
......@@ -9,7 +9,7 @@ import styles.FloorStyle
@Composable
fun floor(floor: Floor, selectedMachine: Machine?, setMachine: (Machine?)->Unit) {
val zIndex = 200 - floor.id*2
val zIndex = 2000 - floor.id*2
Div(attrs = {
classes(FloorStyle.container)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment