aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/app/Page
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-06-06 22:42:44 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-06-06 22:42:44 +0200
commitb1a4822d5954fe02b82f2c525403c74b3920befe (patch)
tree6a284f7ec64dd0bb3bc7ff3e1812139b3a2f3932 /frontend/app/Page
parent612da78d17c575cd5ade1de62dc1a3c514129de0 (diff)
support optional fields
Diffstat (limited to 'frontend/app/Page')
-rw-r--r--frontend/app/Page/EditValue.hs14
1 files changed, 13 insertions, 1 deletions
diff --git a/frontend/app/Page/EditValue.hs b/frontend/app/Page/EditValue.hs
index 294d1c9..d5a87e7 100644
--- a/frontend/app/Page/EditValue.hs
+++ b/frontend/app/Page/EditValue.hs
@@ -10,6 +10,7 @@ where
import Api
import Data.Aeson qualified as A
import Data.Aeson.KeyMap qualified as AM
+import Data.ByteString.Lazy.UTF8 as LB
import Data.Maybe
import Form qualified as F
import Miso
@@ -52,7 +53,8 @@ viewModel m = do
let input = (fromMaybe (A.Object AM.empty) m.input)
div_ [] $
[ viewForm input m.schema,
- viewInput input
+ viewInput input,
+ viewOutput input m.schema
]
viewForm :: A.Value -> Schema -> View Action
@@ -64,3 +66,13 @@ viewForm input =
viewInput :: A.Value -> View Action
viewInput input =
pre_ [] [text (toMisoString (A.encode input))]
+
+viewOutput :: A.Value -> Schema -> View Action
+viewOutput input schema =
+ pre_ [] $
+ [ text $
+ toMisoString
+ ( either ("Left " <>) (("Right " <>) . LB.toString) $
+ (A.encode <$> ((schemaForm schema).fill input))
+ )
+ ]