mirror of
https://github.com/phfroidmont/scalive.git
synced 2025-12-25 05:26:59 +01:00
Add "push" JS command
This commit is contained in:
parent
66c2ac5d71
commit
aaea4f487b
2 changed files with 22 additions and 2 deletions
|
|
@ -100,7 +100,21 @@ object JSCommands:
|
||||||
def popFocus() =
|
def popFocus() =
|
||||||
ops.addOp("pop_focus", Json.Obj.empty)
|
ops.addOp("pop_focus", Json.Obj.empty)
|
||||||
|
|
||||||
def push() = ???
|
def push[A: JsonEncoder](
|
||||||
|
event: A,
|
||||||
|
target: String = "",
|
||||||
|
loading: String = "",
|
||||||
|
pageLoading: Boolean = false
|
||||||
|
) =
|
||||||
|
ops.addOp(
|
||||||
|
"push",
|
||||||
|
Args.Push(
|
||||||
|
event.toJson,
|
||||||
|
Option.when(target.nonEmpty)(target),
|
||||||
|
Option.when(loading.nonEmpty)(loading),
|
||||||
|
Option.when(!pageLoading)(pageLoading)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def pushFocus(to: String = "") =
|
def pushFocus(to: String = "") =
|
||||||
ops.addOp("push_focus", Args.To(Option.when(to.nonEmpty)(to)))
|
ops.addOp("push_focus", Args.To(Option.when(to.nonEmpty)(to)))
|
||||||
|
|
@ -257,6 +271,12 @@ object JSCommands:
|
||||||
time: Option[Int],
|
time: Option[Int],
|
||||||
blocking: Option[Boolean])
|
blocking: Option[Boolean])
|
||||||
derives JsonEncoder
|
derives JsonEncoder
|
||||||
|
final case class Push(
|
||||||
|
event: String,
|
||||||
|
target: Option[String],
|
||||||
|
loading: Option[String],
|
||||||
|
pageLoading: Option[Boolean])
|
||||||
|
derives JsonEncoder
|
||||||
end Args
|
end Args
|
||||||
|
|
||||||
end JSCommands
|
end JSCommands
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ class ListLiveView(someParam: String) extends LiveView[Msg, Model]:
|
||||||
span(cls := "grow"),
|
span(cls := "grow"),
|
||||||
button(
|
button(
|
||||||
cls := "btn btn-neutral",
|
cls := "btn btn-neutral",
|
||||||
phx.click := JS.toggleClass("btn-neutral btn-accent"),
|
phx.click := JS.toggleClass("btn-neutral btn-accent").push(Msg.IncAge(-5)),
|
||||||
"Toggle color"
|
"Toggle color"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue