mirror of
https://github.com/phfroidmont/scalive.git
synced 2025-12-25 05:26:59 +01:00
Fix splitById
This commit is contained in:
parent
21309629bc
commit
1da129f855
6 changed files with 247 additions and 40 deletions
|
|
@ -10,7 +10,7 @@ class TodoLiveView() extends LiveView[Msg, Model]:
|
|||
|
||||
def update(model: Model) =
|
||||
case Msg.Add(text) =>
|
||||
val nextId = model.todos.maxByOption(_.id).map(_.id).getOrElse(1)
|
||||
val nextId = model.todos.maxByOption(_.id).map(_.id).getOrElse(1) + 1
|
||||
ZIO.succeed(
|
||||
model
|
||||
.focus(_.todos)
|
||||
|
|
@ -37,35 +37,34 @@ class TodoLiveView() extends LiveView[Msg, Model]:
|
|||
div(
|
||||
cls := "card-body",
|
||||
h1(cls := "card-title", "Todos"),
|
||||
div(
|
||||
cls := "flex items-center gap-3",
|
||||
input(
|
||||
cls := "input input-bordered grow",
|
||||
typ := "text",
|
||||
nameAttr := "todo-text",
|
||||
placeholder := "What needs to be done?",
|
||||
phx.onKeyup.withValue(Msg.Add(_)),
|
||||
phx.key := "Enter",
|
||||
phx.value("test") := "some value"
|
||||
)
|
||||
),
|
||||
form(
|
||||
cls := "flex items-center gap-3",
|
||||
phx.onChange(p => Msg.Add(p("todo-text"))),
|
||||
phx.onSubmit(p => Msg.Add(p("todo-text"))),
|
||||
phx.onSubmit(p => Msg.Add(p("todo-name"))),
|
||||
input(
|
||||
cls := "input input-bordered grow",
|
||||
typ := "text",
|
||||
nameAttr := "todo-text",
|
||||
placeholder := "What needs to be done?"
|
||||
nameAttr := "todo-name",
|
||||
placeholder := "What needs to be done?",
|
||||
value := model(_.inputText)
|
||||
)
|
||||
),
|
||||
ul(
|
||||
cls := "divide-y divide-base-200",
|
||||
model(_.todos).splitByIndex((_, elem) =>
|
||||
model(_.todos).splitBy(_.id)((id, todo) =>
|
||||
li(
|
||||
cls := "py-3 flex flex-wrap items-center justify-between gap-2",
|
||||
elem(_.text)
|
||||
cls := "py-3 flex items-center gap-3",
|
||||
input(
|
||||
tpe := "checkbox",
|
||||
cls := "checkbox checkbox-primary",
|
||||
checked := todo(_.completed),
|
||||
phx.onClick(Msg.ToggleCompletion(id))
|
||||
),
|
||||
todo(_.text),
|
||||
button(
|
||||
cls := "btn btn-ghost btn-sm text-error",
|
||||
phx.onClick(Msg.Remove(id)),
|
||||
"✕"
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
@ -82,7 +81,10 @@ object TodoLiveView:
|
|||
case Remove(id: Int)
|
||||
case ToggleCompletion(id: Int)
|
||||
|
||||
final case class Model(todos: List[Todo] = List.empty, filter: Filter = Filter.All)
|
||||
final case class Model(
|
||||
todos: List[Todo] = List.empty,
|
||||
inputText: String = "",
|
||||
filter: Filter = Filter.All)
|
||||
final case class Todo(id: Int, text: String, completed: Boolean = false)
|
||||
enum Filter:
|
||||
case All, Active, Completed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue