diff --git a/src/main/scala/app/Base.scala b/src/main/scala/app/Base.scala new file mode 100644 index 0000000..89dfe55 --- /dev/null +++ b/src/main/scala/app/Base.scala @@ -0,0 +1,66 @@ +package app + +import scala.scalajs.js +import org.scalajs.dom +import slinky.core.FunctionalComponent +import slinky.web.html._ +import slinky.core.facade.Hooks._ + +import app.handlers.{Handler, Nothing} + +object Base { + val handlers: List[Handler] = List(Nothing) + + val component = FunctionalComponent[Unit] { props => + val (typedValue, setTypedValue) = useState("") + + useEffect( + () => { + val saved = dom.window.localStorage.getItem("value") + println(s"saved: ${saved}") + setTypedValue(saved match { case _: String => saved; case _ => "" }) + }, + Seq() + ) + + useEffect( + () => { + dom.window.localStorage.setItem("value", typedValue) + }, + Seq(typedValue) + ) + + val Handler = handlers + .find(handler => handler.handles(typedValue)) + .getOrElse(Nothing) + + div( + style := js.Dynamic.literal( + fontFamily = "monospace" + ) + )( + div( + h1("nostr army knife"), + p("paste something nostric"), + textarea( + value := typedValue, + onChange := { ev => setTypedValue(ev.target.value) }, + style := js.Dynamic.literal( + padding = "7px", + width = "100%", + minHeight = "200px" + ) + ) + ), + hr(style := js.Dynamic.literal(margin = "18px 0")), + div( + style := js.Dynamic.literal( + width = "90%", + margin = "auto" + ) + )( + Handler.component(typedValue) + ) + ) + } +} diff --git a/src/main/scala/app/handlers/Handler.scala b/src/main/scala/app/handlers/Handler.scala new file mode 100644 index 0000000..23eb638 --- /dev/null +++ b/src/main/scala/app/handlers/Handler.scala @@ -0,0 +1,8 @@ +package app.handlers + +import slinky.core.FunctionalComponent + +trait Handler { + def handles(value: String): Boolean + val component: FunctionalComponent[String] +} diff --git a/src/main/scala/app/handlers/Nothing.scala b/src/main/scala/app/handlers/Nothing.scala new file mode 100644 index 0000000..7eeb587 --- /dev/null +++ b/src/main/scala/app/handlers/Nothing.scala @@ -0,0 +1,34 @@ +package app.handlers + +import scala.scalajs.js +import slinky.core.FunctionalComponent +import slinky.web.html._ +import slinky.core.facade.Hooks._ +import slinky.core.facade.Fragment + +import app.handlers.{Handler} + +object Nothing extends Handler { + override def handles(value: String): Boolean = true + + override val component = FunctionalComponent[String] { props => + Fragment( + p("you can paste here"), + ul( + li("an unsigned event to be hashed and signed"), + li("a signed event to have its signature checked"), + li("a nostr relay URL to be inspected"), + li("a nostr event id we'll try to fetch"), + li("a nip05 identifier to be checked"), + li( + span("contribute a new function: "), + a( + target := "_blank", + href := "https://github.com/fiatjaf/nostr-army-knife", + style := js.Dynamic.literal(color = "inherit") + )("_______") + ) + ) + ) + } +} diff --git a/src/main/scala/app/main.scala b/src/main/scala/app/main.scala index f1f7dc1..79da934 100644 --- a/src/main/scala/app/main.scala +++ b/src/main/scala/app/main.scala @@ -4,15 +4,16 @@ import org.scalajs.dom.document import slinky.web.ReactDOM import slinky.web.html._ +import app.Base._ + object Main { def main(args: Array[String]): Unit = { val div = document.createElement("div") div.id = "root" document.body.appendChild(div) - println("Hello!") ReactDOM.render( - h1("Hello, world?"), + Base.component(), document.getElementById("root") ) }