Add home liveview

This commit is contained in:
Paul-Henri Froidmont 2025-09-13 01:36:30 +02:00
parent a036e3cbb3
commit 0b067aa7e1
Signed by: phfroidmont
GPG key ID: BE948AFD7E7873BE
3 changed files with 43 additions and 4 deletions

View file

@ -25,6 +25,10 @@ object Example extends ZIOAppDefault:
LiveRouter(
RootLayout(_),
List(
LiveRoute(
Root,
(_, _) => HomeLiveView()
),
LiveRoute(
Root / "counter",
(_, _) => CounterLiveView()

View file

@ -0,0 +1,29 @@
import scalive.*
import zio.*
import zio.stream.ZStream
class HomeLiveView() extends LiveView[String, Unit]:
val links = List(
"/counter" -> "Counter",
"/list" -> "List"
)
def init = ZIO.succeed(())
def update(model: Unit) = _ => ZIO.succeed(model)
def view(model: Dyn[Unit]) =
ul(
cls := "space-y-2",
links.map((path, name) =>
li(
a(
href := path,
cls := "block px-4 py-2 rounded-lg text-gray-700 hover:bg-gray-100 hover:text-gray-900 font-medium transition",
name
)
)
)
)
def subscriptions(model: Unit) = ZStream.empty