format action and styling quibbles.

This commit is contained in:
fiatjaf 2023-03-24 07:25:31 -03:00
parent 6ea1475759
commit b966c8a1ac
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 57 additions and 25 deletions

View File

@ -9,8 +9,10 @@ import io.circe.syntax.*
import calico.* import calico.*
import calico.html.io.{*, given} import calico.html.io.{*, given}
import calico.syntax.* import calico.syntax.*
import snow.*
import scoin.* import scoin.*
import snow.*
import Utils.*
object Store { object Store {
def apply(window: Window[IO]): Resource[IO, Store] = { def apply(window: Window[IO]): Resource[IO, Store] = {
@ -55,11 +57,31 @@ object Main extends IOWebApp {
cls := "w-4/5", cls := "w-4/5",
h1(cls := "px-1 py-2 text-center text-xl", "nostr army knife"), h1(cls := "px-1 py-2 text-center text-xl", "nostr army knife"),
div( div(
cls := "flex justify-center my-3", cls := "flex my-3",
input(store), input(store),
actions(store)
),
result(store)
)
)
}
def actions(store: Store): Resource[IO, HtmlDivElement[IO]] =
div(
cls := "flex flex-col space-y-1 my-3",
button( button(
cls := Styles.button,
"shrink bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 mx-2 px-4 rounded ", "format",
onClick --> (_.foreach(_ =>
store.input.update(original =>
parse(original).toOption
.map(_.printWith(jsonPrinter))
.getOrElse(original)
)
))
),
button(
Styles.button,
"generate event", "generate event",
onClick --> (_.foreach(_ => onClick --> (_.foreach(_ =>
store.input.set( store.input.set(
@ -68,15 +90,11 @@ object Main extends IOWebApp {
content = "hello world" content = "hello world"
).sign(PrivateKey(randomBytes32())) ).sign(PrivateKey(randomBytes32()))
.asJson .asJson
.printWith(Utils.jsonPrinter) .printWith(jsonPrinter)
) )
)) ))
) )
),
result(store)
) )
)
}
def input(store: Store): Resource[IO, HtmlDivElement[IO]] = def input(store: Store): Resource[IO, HtmlDivElement[IO]] =
div( div(
@ -86,7 +104,7 @@ object Main extends IOWebApp {
textArea.withSelf { self => textArea.withSelf { self =>
( (
cls := "w-full max-h-96 p-3 rounded", cls := "w-full max-h-96 p-3 rounded",
styleAttr := "min-height: 400px", styleAttr := "min-height: 280px; font-family: monospace",
placeholder := "paste something nostric", placeholder := "paste something nostric",
onInput --> (_.foreach(_ => onInput --> (_.foreach(_ =>
self.value.get.flatMap(store.input.set) self.value.get.flatMap(store.input.set)
@ -114,27 +132,34 @@ object Main extends IOWebApp {
case Right(event) => case Right(event) =>
div( div(
cls := "text-md", cls := "text-md",
styleAttr := "font-family: monospace",
div( div(
span(cls := "font-bold", "serialized event "), span(cls := "font-bold", "serialized event "),
event.serialized span(Styles.mono, event.serialized)
), ),
div( div(
span(cls := "font-bold", "implied event id "), span(cls := "font-bold", "implied event id "),
event.hash.toHex span(Styles.mono, event.hash.toHex)
), ),
div( div(
span( span(
cls := "font-bold", cls := "font-bold",
"does the implied event id match the given event id? " "does the implied event id match the given event id? "
), ),
span(
Styles.mono,
event.id == event.hash.toHex match { event.id == event.hash.toHex match {
case true => "yes"; case false => "no" case true => "yes"; case false => "no"
} }
)
), ),
div( div(
span(cls := "font-bold", "is signature valid? "), span(cls := "font-bold", "is signature valid? "),
event.isValid match { case true => "yes"; case false => "no" } span(
Styles.mono,
event.isValid match {
case true => "yes"; case false => "no"
}
)
) )
) )
} }

View File

@ -0,0 +1,7 @@
import calico.html.io.*
object Styles {
val button = cls :=
"shrink bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 mx-2 px-4 rounded "
val mono = styleAttr := "font-family: monospace"
}