From 4d23a4c6af8053208032139ca6c5a10b5024ea2c Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Fri, 24 Mar 2023 22:14:45 -0300 Subject: [PATCH] format button only when there is a JSON element. --- src/main/scala/Main.scala | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/scala/Main.scala b/src/main/scala/Main.scala index 579eb51..ec53c34 100644 --- a/src/main/scala/Main.scala +++ b/src/main/scala/Main.scala @@ -35,17 +35,21 @@ object Main extends IOWebApp { def actions(store: Store): Resource[IO, HtmlDivElement[IO]] = div( cls := "flex flex-col space-y-1 my-3", - button( - Styles.button, - "format", - onClick --> (_.foreach(_ => - store.input.update(original => - parse(original).toOption - .map(_.printWith(jsonPrinter)) - .getOrElse(original) + store.result.map { + case Right(_: Event) => + button( + Styles.button, + "format", + onClick --> (_.foreach(_ => + store.input.update(original => + parse(original).toOption + .map(_.printWith(jsonPrinter)) + .getOrElse(original) + ) + )) ) - )) - ), + case _ => div("") + }, button( Styles.button, "generate event",