mirror of
https://github.com/fiatjaf/nak.git
synced 2025-12-10 09:28:51 +00:00
just arranging things.
This commit is contained in:
27
src/main/scala/Generator.scala
Normal file
27
src/main/scala/Generator.scala
Normal file
@@ -0,0 +1,27 @@
|
||||
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 Generator {
|
||||
def apply(): Resource[IO, HtmlDivElement[IO]] =
|
||||
SignallingRef[IO]
|
||||
.of("")
|
||||
.toResource
|
||||
.flatMap { input =>
|
||||
div(
|
||||
cls := "my-3",
|
||||
button(cls := buttonCls, "generate event"),
|
||||
button(cls := buttonCls, "generate keypair")
|
||||
)
|
||||
}
|
||||
|
||||
val buttonCls =
|
||||
"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 mx-2 px-4 rounded"
|
||||
}
|
||||
@@ -16,20 +16,34 @@ object Input {
|
||||
.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
|
||||
)
|
||||
},
|
||||
cls := "w-full",
|
||||
div(
|
||||
cls := "w-full flex justify-center",
|
||||
textArea.withSelf { self =>
|
||||
(
|
||||
cls := "w-2/3 max-h-96 p-3",
|
||||
styleAttr := "min-height: 200px",
|
||||
placeholder := "paste something nostric",
|
||||
onInput --> (_.foreach(_ => self.value.get.flatMap(input.set))),
|
||||
value <-- input
|
||||
)
|
||||
}
|
||||
),
|
||||
div(
|
||||
cls := "w-full flex justify-center",
|
||||
input.map(inp =>
|
||||
decode[Event](inp) match {
|
||||
case Left(err) => err.toString
|
||||
case Right(event) => event.toString
|
||||
}
|
||||
if inp.trim() == "" then ""
|
||||
else
|
||||
decode[Event](inp) match {
|
||||
case Right(event) => event.toString
|
||||
case Left(err: io.circe.DecodingFailure) =>
|
||||
err.pathToRootString match {
|
||||
case Some(path) => s"field $path is missing or wrong"
|
||||
case None => s"decoding ${err.pathToRootString}"
|
||||
}
|
||||
case Left(err: io.circe.ParsingFailure) =>
|
||||
"not valid JSON"
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -8,6 +8,7 @@ object Main extends IOWebApp {
|
||||
def render: Resource[IO, HtmlDivElement[IO]] = div(
|
||||
cls := "flex w-full h-full flex-col items-center justify-center",
|
||||
h1(cls := "px-1 py-2 text-lg", "nostr army knife"),
|
||||
Input()
|
||||
Input(),
|
||||
Generator()
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user