mirror of
https://github.com/fiatjaf/nak.git
synced 2024-11-22 16:19:07 -05:00
first Handler component: Nothing.
This commit is contained in:
parent
ab841df209
commit
df814a98e7
66
src/main/scala/app/Base.scala
Normal file
66
src/main/scala/app/Base.scala
Normal file
|
@ -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)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
8
src/main/scala/app/handlers/Handler.scala
Normal file
8
src/main/scala/app/handlers/Handler.scala
Normal file
|
@ -0,0 +1,8 @@
|
|||
package app.handlers
|
||||
|
||||
import slinky.core.FunctionalComponent
|
||||
|
||||
trait Handler {
|
||||
def handles(value: String): Boolean
|
||||
val component: FunctionalComponent[String]
|
||||
}
|
34
src/main/scala/app/handlers/Nothing.scala
Normal file
34
src/main/scala/app/handlers/Nothing.scala
Normal file
|
@ -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")
|
||||
)("_______")
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
|
@ -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")
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user