mirror of
https://github.com/fiatjaf/nak.git
synced 2024-12-22 18:15:51 -05:00
basic parsing nostr events from input.
This commit is contained in:
parent
b54ae5f8fb
commit
61bf4e6ed0
|
@ -1,7 +1,7 @@
|
|||
<meta charset=utf-8>
|
||||
<title>nostr army knife</title>
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<body class="bg-emerald-200 text-black m-0">
|
||||
<div id="app"></div>
|
||||
<body class="bg-emerald-200 text-black m-0 w-full h-full">
|
||||
<div id="app" class="w-full h-full"></div>
|
||||
<script type="module" src="/target/esbuild/bundle.js"></script>
|
||||
</body>
|
||||
|
|
38
src/main/scala/Input.scala
Normal file
38
src/main/scala/Input.scala
Normal file
|
@ -0,0 +1,38 @@
|
|||
import cats.effect.*
|
||||
import cats.effect.syntax.all.*
|
||||
import cats.syntax.all.*
|
||||
import fs2.concurrent.*
|
||||
import fs2.dom.{Event => _, *}
|
||||
import io.circe.parser.*
|
||||
import calico.*
|
||||
import calico.html.io.{*, given}
|
||||
import calico.syntax.*
|
||||
import snow.*
|
||||
|
||||
object Input {
|
||||
def apply(): Resource[IO, HtmlDivElement[IO]] =
|
||||
SignallingRef[IO]
|
||||
.of("")
|
||||
.toResource
|
||||
.flatMap { input =>
|
||||
div(
|
||||
textArea.withSelf { self =>
|
||||
(
|
||||
cls := "w-2/3 min-h-fit max-h-96 p-3",
|
||||
placeholder := "paste something nostric",
|
||||
onInput --> (_.foreach(_ => self.value.get.flatMap(input.set))),
|
||||
value <-- input
|
||||
)
|
||||
},
|
||||
div(
|
||||
input.map(inp =>
|
||||
decode[Event](inp) match {
|
||||
case Left(err) => err.toString
|
||||
case Right(event) => event.toString
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
|
@ -1,63 +1,13 @@
|
|||
import cats.effect.*
|
||||
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)
|
||||
cls := "flex w-full h-full flex-col items-center justify-center",
|
||||
h1(cls := "px-1 py-2 text-lg", "nostr army knife"),
|
||||
Input()
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user