From 892b2122b8b0128c1287b3bd5d2f3af9d4b6ba0f Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 23 Feb 2022 16:30:40 -0300 Subject: [PATCH] key handler (except the nostr part). --- src/main/scala/app/Base.scala | 5 ++-- src/main/scala/app/components/Item.scala | 29 +++++++++++++++++++ .../scala/app/handlers/EventSignatures.scala | 21 ++++++++++++++ src/main/scala/app/handlers/KeyHandling.scala | 25 ++++++++++++++++ 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 src/main/scala/app/components/Item.scala create mode 100644 src/main/scala/app/handlers/EventSignatures.scala create mode 100644 src/main/scala/app/handlers/KeyHandling.scala diff --git a/src/main/scala/app/Base.scala b/src/main/scala/app/Base.scala index 89dfe55..32ac6c6 100644 --- a/src/main/scala/app/Base.scala +++ b/src/main/scala/app/Base.scala @@ -6,10 +6,10 @@ import slinky.core.FunctionalComponent import slinky.web.html._ import slinky.core.facade.Hooks._ -import app.handlers.{Handler, Nothing} +import app.handlers.{Handler, Nothing, KeyHandling} object Base { - val handlers: List[Handler] = List(Nothing) + val handlers: List[Handler] = List(KeyHandling, Nothing) val component = FunctionalComponent[Unit] { props => val (typedValue, setTypedValue) = useState("") @@ -17,7 +17,6 @@ object Base { useEffect( () => { val saved = dom.window.localStorage.getItem("value") - println(s"saved: ${saved}") setTypedValue(saved match { case _: String => saved; case _ => "" }) }, Seq() diff --git a/src/main/scala/app/components/Item.scala b/src/main/scala/app/components/Item.scala new file mode 100644 index 0000000..fb3ee94 --- /dev/null +++ b/src/main/scala/app/components/Item.scala @@ -0,0 +1,29 @@ +package app.components + +import scala.scalajs.js +import slinky.core.{FunctionalComponent, CustomAttribute} +import slinky.web.html._ + +object Item { + val wenkValue = CustomAttribute[String]("data-wenk") + val wenkPos = CustomAttribute[String]("data-wenk-pos") + + case class props(label: String, hint: String, content: String) + + val component = FunctionalComponent[props] { props => + div( + style := js.Dynamic.literal( + marginBottom = "9px", + whiteSpace = "pre-wrap", + wordWrap = "break-word", + wordBreak = "break-all" + ) + )( + b(wenkValue := props.hint, wenkPos := "right")( + span(props.label) + ), + span(" "), + span(props.content) + ) + } +} diff --git a/src/main/scala/app/handlers/EventSignatures.scala b/src/main/scala/app/handlers/EventSignatures.scala new file mode 100644 index 0000000..240710d --- /dev/null +++ b/src/main/scala/app/handlers/EventSignatures.scala @@ -0,0 +1,21 @@ +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 io.circe._ +import io.circe.parser._ + +import app.handlers.{Handler} + +object EventSignatures extends Handler { + override def handles(value: String): Boolean = false + + override val component = FunctionalComponent[String] { props => + Fragment( + "nada" + ) + } +} diff --git a/src/main/scala/app/handlers/KeyHandling.scala b/src/main/scala/app/handlers/KeyHandling.scala new file mode 100644 index 0000000..98fa0df --- /dev/null +++ b/src/main/scala/app/handlers/KeyHandling.scala @@ -0,0 +1,25 @@ +package app.handlers + +import scala.util.matching.Regex +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} +import app.components.{Item} + +object KeyHandling extends Handler { + val keymatcher = "^[a-f0-9]{64}$".r + + override def handles(value: String): Boolean = + keymatcher.matches(value.toLowerCase()) + + override val component = FunctionalComponent[String] { props => + Fragment( + Item.component(Item.props("private key", "", props)), + Item.component(Item.props("public key", "", "soon to be shown here")) + ) + } +}