From b1a4822d5954fe02b82f2c525403c74b3920befe Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Thu, 6 Jun 2024 22:42:44 +0200 Subject: support optional fields --- frontend/app/Page/EditValue.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'frontend/app/Page') 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)) + ) + ] -- cgit v1.2.3