From f41de5487d3e6723d4a5251506b6c4e4c0cc7cee Mon Sep 17 00:00:00 2001 From: John O'Reilly Date: Fri, 5 Feb 2021 18:03:17 +0000 Subject: [PATCH] show iss position in kotlin/js client --- web/src/main/kotlin/App.kt | 15 +++++++++++++-- web/src/main/kotlin/Main.kt | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/web/src/main/kotlin/App.kt b/web/src/main/kotlin/App.kt index 4ee30f0..4c9437e 100644 --- a/web/src/main/kotlin/App.kt +++ b/web/src/main/kotlin/App.kt @@ -1,21 +1,28 @@ import com.surrus.common.remote.Assignment +import com.surrus.common.remote.IssPosition import react.* import react.dom.* import kotlinx.coroutines.* +import kotlinx.coroutines.flow.collect - -val App = functionalComponent { _ -> +@InternalCoroutinesApi +val App = functionalComponent { val appDependencies = useContext(AppDependenciesContext) val repository = appDependencies.repository val (people, setPeople) = useState(emptyList()) + val (issPosition, setIssPosition) = useState(IssPosition(0.0,0.0)) useEffectWithCleanup(dependencies = listOf()) { val mainScope = MainScope() mainScope.launch { setPeople(repository.fetchPeople()) + + repository.pollISSPosition().collect { + setIssPosition(it) + } } return@useEffectWithCleanup { mainScope.cancel() } } @@ -23,6 +30,9 @@ val App = functionalComponent { _ -> h1 { +"People In Space" } + h2 { + +"$issPosition" + } ul { people.forEach { item -> li { @@ -30,4 +40,5 @@ val App = functionalComponent { _ -> } } } + } diff --git a/web/src/main/kotlin/Main.kt b/web/src/main/kotlin/Main.kt index 4ce8075..d3ec879 100644 --- a/web/src/main/kotlin/Main.kt +++ b/web/src/main/kotlin/Main.kt @@ -1,6 +1,7 @@ import co.touchlab.kermit.Kermit import com.surrus.common.di.initKoin import com.surrus.common.repository.PeopleInSpaceRepository +import kotlinx.coroutines.InternalCoroutinesApi import org.koin.core.KoinComponent import org.koin.core.get import react.child @@ -21,6 +22,7 @@ object AppDependencies : KoinComponent { val AppDependenciesContext = createContext() +@InternalCoroutinesApi fun main() { render(kotlinx.browser.document.getElementById("root")) { AppDependenciesContext.Provider(AppDependencies) {