From 140d3ec137d9e8a46cb8181b5cfd6e421c94f967 Mon Sep 17 00:00:00 2001 From: Sebastian Aigner Date: Wed, 5 Feb 2020 13:25:27 +0100 Subject: [PATCH 1/6] 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 | 67 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt index 15f7cf0..4dc17a3 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -1,5 +1,70 @@ +import react.dom.* import kotlinx.browser.document +import kotlinx.css.* +import styled.* + +external interface Video { + val id: Int + val title: String + val speaker: String + val videoUrl: String +} + +data class KotlinVideo( + override val id: Int, + override val title: String, + override val speaker: String, + override val videoUrl: String +) : Video + +val unwatchedVideos = listOf( + KotlinVideo(1, "Building and breaking things", "John Doe", "https://youtu.be/PsaFVLr8t4E"), + KotlinVideo(2, "The development process", "Jane Smith", "https://youtu.be/PsaFVLr8t4E"), + KotlinVideo(3, "The Web 7.0", "Matt Miller", "https://youtu.be/PsaFVLr8t4E") +) + +val watchedVideos = listOf( + KotlinVideo(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 e71f1642969041805f0575ae452a38e70d061838 Mon Sep 17 00:00:00 2001 From: Sebastian Aigner Date: Wed, 5 Feb 2020 13:53:04 +0100 Subject: [PATCH 2/6] Move HTML to App component Introduce VideoList component with selection mechanism (state and properties) --- src/main/kotlin/App.kt | 44 ++++++++++++++++++++++++++++++++++++ src/main/kotlin/Main.kt | 38 +------------------------------ src/main/kotlin/VideoList.kt | 41 +++++++++++++++++++++++++++++++++ 3 files changed, 86 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..927bcdc --- /dev/null +++ b/src/main/kotlin/App.kt @@ -0,0 +1,44 @@ +import kotlinx.css.* +import react.* +import react.dom.* +import styled.css +import styled.styledDiv + +@JsExport +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 4dc17a3..56b4947 100644 --- a/src/main/kotlin/Main.kt +++ b/src/main/kotlin/Main.kt @@ -29,42 +29,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..83402d5 --- /dev/null +++ b/src/main/kotlin/VideoList.kt @@ -0,0 +1,41 @@ +import kotlinx.html.js.onClickFunction +import kotlinx.browser.window +import react.* +import react.dom.* + + +external interface VideoListProps: RProps { + var videos: List