mirror of
https://github.com/fiatjaf/nak.git
synced 2024-10-30 00:59:07 -04:00
copypaste calico example running.
This commit is contained in:
parent
9366b3820a
commit
b54ae5f8fb
|
@ -1,2 +1,2 @@
|
|||
version = 3.4.3
|
||||
runner.dialect = scala213
|
||||
runner.dialect = scala3
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
enablePlugins(ScalaJSPlugin)
|
||||
enablePlugins(ScalaJSPlugin, EsbuildPlugin)
|
||||
|
||||
name := "nostr-army-knife"
|
||||
scalaVersion := "2.13.7"
|
||||
scalaVersion := "3.2.2"
|
||||
|
||||
scalaJSUseMainModuleInitializer := true
|
||||
|
||||
libraryDependencies += "com.armanbilge" %%% "calico" % "0.2.0-RC2"
|
||||
libraryDependencies += "com.fiatjaf" %%% "snow" % "0.2.0-RC2"
|
||||
libraryDependencies += "com.fiatjaf" %%% "snow" % "0.0.1-SNAPSHOT"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<meta charset=utf-8>
|
||||
<title>nostr army knife</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<body class="bg-amber-600 text-white m-0">
|
||||
<main id="main" />
|
||||
<script src=/target/esbuild/bundle.js></script>
|
||||
<body class="bg-emerald-200 text-black m-0">
|
||||
<div id="app"></div>
|
||||
<script type="module" src="/target/esbuild/bundle.js"></script>
|
||||
</body>
|
||||
|
|
|
@ -1 +1,63 @@
|
|||
import calico.*
|
||||
import calico.html.io.{*, given}
|
||||
import calico.syntax.*
|
||||
import calico.unsafe.given
|
||||
import cats.effect.*
|
||||
import cats.effect.syntax.all.*
|
||||
import cats.syntax.all.*
|
||||
import fs2.*
|
||||
import fs2.concurrent.*
|
||||
import fs2.dom.*
|
||||
|
||||
object Main extends IOWebApp {
|
||||
def Counter(
|
||||
label: String,
|
||||
initialStep: Int
|
||||
): Resource[IO, HtmlDivElement[IO]] =
|
||||
SignallingRef[IO]
|
||||
.of(initialStep)
|
||||
.product(Channel.unbounded[IO, Int])
|
||||
.toResource
|
||||
.flatMap { (step, diff) =>
|
||||
val allowedSteps = List(1, 2, 3, 5, 10)
|
||||
|
||||
div(
|
||||
p(
|
||||
"Step: ",
|
||||
select.withSelf { self =>
|
||||
(
|
||||
allowedSteps
|
||||
.map(step => option(value := step.toString, step.toString)),
|
||||
value <-- step.map(_.toString),
|
||||
onChange --> {
|
||||
_.evalMap(_ => self.value.get)
|
||||
.map(_.toIntOption)
|
||||
.unNone
|
||||
.foreach(step.set)
|
||||
}
|
||||
)
|
||||
}
|
||||
),
|
||||
p(
|
||||
label + ": ",
|
||||
b(diff.stream.scanMonoid.map(_.toString).holdOptionResource),
|
||||
" ",
|
||||
button(
|
||||
"-",
|
||||
onClick --> {
|
||||
_.evalMap(_ => step.get).map(-1 * _).foreach(diff.send(_).void)
|
||||
}
|
||||
),
|
||||
button(
|
||||
"+",
|
||||
onClick --> (_.evalMap(_ => step.get).foreach(diff.send(_).void))
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def render: Resource[IO, HtmlDivElement[IO]] = div(
|
||||
h1("Let's count!"),
|
||||
Counter("Sheep", initialStep = 3)
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user