mirror of
https://github.com/fiatjaf/nak.git
synced 2024-11-22 16:19:07 -05:00
get everything into a single file again -- and now I don't know how to connect the things in a nice global shared state because that is not allowed.
This commit is contained in:
parent
892f06fb98
commit
fa7c9b632a
|
@ -1,27 +0,0 @@
|
|||
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"
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
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(
|
||||
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 =>
|
||||
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"
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
|
@ -1,14 +1,73 @@
|
|||
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 fs2.dom.*
|
||||
import snow.*
|
||||
|
||||
object Main extends IOWebApp {
|
||||
def render: Resource[IO, HtmlDivElement[IO]] = div(
|
||||
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(),
|
||||
Generator()
|
||||
div(
|
||||
cls := "flex justify-center my-3"
|
||||
// button(cls := buttonCls, "generate event", onClick --> (_.foreach(_ => ))),
|
||||
),
|
||||
input()
|
||||
)
|
||||
}
|
||||
|
||||
def input(): Resource[IO, HtmlDivElement[IO]] =
|
||||
SignallingRef[IO]
|
||||
.of("")
|
||||
.toResource
|
||||
.flatMap { input =>
|
||||
div(
|
||||
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
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def result(): Resource[IO, HtmlDivElement[IO]] =
|
||||
SignallingRef[IO]
|
||||
.of("")
|
||||
.toResource
|
||||
.flatMap { input =>
|
||||
div(
|
||||
cls := "w-full flex justify-center",
|
||||
input.map(inp =>
|
||||
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"
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
val buttonCls =
|
||||
"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 mx-2 px-4 rounded"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user