From 92f9a060085046d0a1cf4970284554b19c55bcb2 Mon Sep 17 00:00:00 2001 From: Nekoyue Date: Thu, 2 Apr 2020 20:16:09 +0800 Subject: [PATCH 01/14] Update kotlin and reactjs. --- build.gradle.kts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 384f5d5..b16c0eb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,13 +16,13 @@ dependencies { implementation(kotlin("stdlib-js")) //React, React DOM + Wrappers (chapter 3) - implementation("org.jetbrains:kotlin-react:16.9.0-pre.89-kotlin-1.3.60") - implementation("org.jetbrains:kotlin-react-dom:16.9.0-pre.89-kotlin-1.3.60") - implementation(npm("react", "16.12.0")) - implementation(npm("react-dom", "16.12.0")) + implementation("org.jetbrains:kotlin-react:16.13.0-pre.94-kotlin-1.3.70") + implementation("org.jetbrains:kotlin-react-dom:16.13.0-pre.94-kotlin-1.3.70") + implementation(npm("react", "16.13.1")) + implementation(npm("react-dom", "16.13.1")) //Kotlin Styled (chapter 3) - implementation("org.jetbrains:kotlin-styled:1.0.0-pre.90-kotlin-1.3.61") + implementation("org.jetbrains:kotlin-styled:1.0.0-pre.94-kotlin-1.3.70") implementation(npm("styled-components")) implementation(npm("inline-style-prefixer")) @@ -33,7 +33,7 @@ dependencies { implementation(npm("react-share")) //Coroutines (chapter 8) - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.3") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.3.5") } kotlin.target.browser { } \ No newline at end of file From 13ec914bc77cac4cd0ede4c29d5761ce9531f5c4 Mon Sep 17 00:00:00 2001 From: Sebastian Aigner Date: Wed, 5 Feb 2020 13:25:27 +0100 Subject: [PATCH 02/14] Add typesafe HTML representation of website Use styled components Add Video data class and example lists for unwatched and watched videos --- src/main/kotlin/Main.kt | 55 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index efa3a07..3b5d9a8 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,5 +1,58 @@ +import react.dom.* import kotlin.browser.document +import kotlinx.css.* +import styled.* + +data class Video(val id: Int, val title: String, val speaker: String, val videoUrl: String) + +val unwatchedVideos = listOf( + Video(1, "Building and breaking things", "John Doe", "https://youtu.be/PsaFVLr8t4E"), + Video(2, "The development process", "Jane Smith", "https://youtu.be/PsaFVLr8t4E"), + Video(3, "The Web 7.0", "Matt Miller", "https://youtu.be/PsaFVLr8t4E") +) + +val watchedVideos = listOf( + Video(4, "Mouseless development", "Tom Jerry", "https://youtu.be/PsaFVLr8t4E") +) fun main() { - document.bgColor = "blue" + render(document.getElementById("root")) { + h1 { + +"KotlinConf Explorer" + } + div { + h3 { + +"Videos to watch" + } + for(video in unwatchedVideos) { + p { + +"${video.speaker}: ${video.title}" + } + } + + h3 { + +"Videos watched" + } + for(video in watchedVideos) { + p { + +"${video.speaker}: ${video.title}" + } + } + } + styledDiv { + css { + position = Position.absolute + top = 10.px + right = 10.px + } + h3 { + +"John Doe: Building and breaking things" + } + img { + attrs { + src = "https://via.placeholder.com/640x360.png?text=Video+Player+Placeholder" + } + } + } + } } \ No newline at end of file From daf1370b93fe6ca716830c44a84e771cc4c423f2 Mon Sep 17 00:00:00 2001 From: Sebastian Aigner Date: Wed, 5 Feb 2020 13:53:04 +0100 Subject: [PATCH 03/14] Move HTML to App component Introduce VideoList component with selection mechanism (state and properties) --- src/main/kotlin/App.kt | 43 ++++++++++++++++++++++++++++++++++++ src/main/kotlin/Main.kt | 38 +------------------------------ src/main/kotlin/VideoList.kt | 40 +++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 37 deletions(-) create mode 100644 src/main/kotlin/App.kt create mode 100644 src/main/kotlin/VideoList.kt diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt new file mode 100644 index 0000000..accd6a9 --- /dev/null +++ b/src/main/kotlin/App.kt @@ -0,0 +1,43 @@ +import kotlinx.css.* +import react.* +import react.dom.* +import styled.css +import styled.styledDiv + +class App : RComponent() { + override fun RBuilder.render() { + h1 { + +"KotlinConf Explorer" + } + div { + h3 { + +"Videos to watch" + } + videoList { + videos = unwatchedVideos + } + + h3 { + +"Videos watched" + } + videoList { + videos = watchedVideos + } + } + styledDiv { + css { + position = Position.absolute + top = 10.px + right = 10.px + } + h3 { + +"John Doe: Building and breaking things" + } + img { + attrs { + src = "https://via.placeholder.com/640x360.png?text=Video+Player+Placeholder" + } + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 3b5d9a8..cca790c 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -17,42 +17,6 @@ val watchedVideos = listOf( fun main() { render(document.getElementById("root")) { - h1 { - +"KotlinConf Explorer" - } - div { - h3 { - +"Videos to watch" - } - for(video in unwatchedVideos) { - p { - +"${video.speaker}: ${video.title}" - } - } - - h3 { - +"Videos watched" - } - for(video in watchedVideos) { - p { - +"${video.speaker}: ${video.title}" - } - } - } - styledDiv { - css { - position = Position.absolute - top = 10.px - right = 10.px - } - h3 { - +"John Doe: Building and breaking things" - } - img { - attrs { - src = "https://via.placeholder.com/640x360.png?text=Video+Player+Placeholder" - } - } - } + child(App::class) {} } } \ No newline at end of file diff --git a/src/main/kotlin/VideoList.kt b/src/main/kotlin/VideoList.kt new file mode 100644 index 0000000..2b474f1 --- /dev/null +++ b/src/main/kotlin/VideoList.kt @@ -0,0 +1,40 @@ +import kotlinx.html.js.onClickFunction +import kotlin.browser.window +import react.* +import react.dom.* + + +interface VideoListProps: RProps { + var videos: List