Untitled
Anonymous
kotlin
04/25/2023 9:07 PM
1.7 KB
15
Indexable
private val scope = MainScope()
val App = FC<Props> {
var shoppingList by useState(emptyList<ShoppingListItem>())
val deleted by useState(mutableListOf<ShoppingListItem>())
useEffectOnce {
scope.launch {
shoppingList = getShoppingList()
}
}
h1 {
+"Full-Stack Shopping List"
}
ul {
shoppingList.sortedByDescending(ShoppingListItem::priority).forEach { item ->
li {
if (item in deleted) {
css {
textDecoration = TextDecoration.lineThrough
}
}
key = item.toString()
onClick = {
scope.launch {
deleted.add(item)
shoppingList = getShoppingList()
}
}
+"[${item.priority}] ${item.desc}"
}
}
}
InputComponent {
onSubmit = { input ->
val cartItem = ShoppingListItem(
input.replace("!", ""),
input.count { it == '!' }
)
scope.launch {
addShoppingListItem(cartItem)
shoppingList = getShoppingList()
}
}
}
}Editor is loading...