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