Last active
August 6, 2017 15:48
-
-
Save sanity/eff39fc67ca495564607529a349a7cb6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
val random = Random() | |
Kweb(port = 1544, refreshPageOnHotswap = true, plugins = listOf(semanticUIPlugin)) { | |
data class TodoItem( | |
val id: String, | |
val description: String, | |
val done: Boolean, | |
val deleted: Boolean | |
) | |
val items = Shoebox<TodoItem>() | |
val activeItems = items | |
.view("deleted", { it.deleted.toString() }) | |
.orderedSet("false", compareBy { it.id }) | |
val s get() = semantic | |
doc.body.new { | |
div(s.ui.centered.container).new { | |
div(s.ui.grid).new { | |
h1(s.ui.header).text("To-do list") | |
div(s.ui.list).new { | |
renderEach(activeItems) { item -> | |
div(s.item).new { | |
div(s.content).new { | |
span(s.header).text(item.map(TodoItem::description)) | |
div(s.extra).new { | |
div(s.right.floated.primary.button).let { button -> | |
button.text("Remove") | |
button.on.click { | |
items.remove(item.value.id) | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
div(s.ui.action.input).new { | |
val newItemInput = input(type = InputType.text, placeholder = "New Item") | |
button(s.ui.button).let { button -> | |
button.new { | |
i(s.add.circle.icon) | |
} | |
button.on.click { | |
launch(CommonPool) { | |
val description = newItemInput.getValue().await() | |
newItemInput.setValue("") | |
if (description.trim() != "") { | |
val newId = random.nextInt(Integer.MAX_VALUE).toString(16) | |
items[newId] = TodoItem(newId, description, false, false) | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment