aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/app/Main.hs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-06-04 09:59:10 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-06-04 09:59:10 +0200
commit9d3c32956baab4dc4e1fd114e586b48d850a14c9 (patch)
treed0de8ff50ffe9bfaeeebc58fbca9a76157614fef /frontend/app/Main.hs
parent342ebdf61b3b9021b9e58cfce607e96a6e7ae54e (diff)
show form input
Diffstat (limited to 'frontend/app/Main.hs')
-rw-r--r--frontend/app/Main.hs40
1 files changed, 23 insertions, 17 deletions
diff --git a/frontend/app/Main.hs b/frontend/app/Main.hs
index 45b828b..356aa6e 100644
--- a/frontend/app/Main.hs
+++ b/frontend/app/Main.hs
@@ -29,7 +29,8 @@ import Miso.String (toMisoString)
data Model = Model
{ schema :: Maybe (Either String Schema),
- posts :: Maybe (Either String [A.Value])
+ posts :: Maybe (Either String [A.Value]),
+ input :: Maybe A.Value
}
deriving (Show, Eq, Generic, Default)
@@ -111,8 +112,10 @@ updateModel action m =
let setPosts :: Either String [A.Value] -> Model -> Model
setPosts posts m = m {posts = Just posts}
in noEff (setPosts posts m)
- FormChanged _ -> noEff m
- FormSubmitted _ -> noEff m
+ FormChanged (Just -> input) -> noEff m {input}
+ FormSubmitted output ->
+ m <# do
+ const NoOp <$> consoleLog (toMisoString (A.encode output))
fetchSchema :: JSM (Either String Schema)
fetchSchema =
@@ -157,20 +160,13 @@ getResponseBody = fromMaybe "" . contents
viewModel :: Model -> View Action
viewModel model =
- div_ [] $
- [ maybe (text "..") (either err viewSchema) model.schema,
- maybe (text "..") (either err viewPosts) model.posts,
- maybe
- (text "..")
- ( either
- err
- ( fmap (either FormChanged FormSubmitted)
- . flip F.runForm (A.Object AM.empty)
- . schemaForm
- )
- )
- model.schema
- ]
+ let input = fromMaybe (A.Object AM.empty) model.input
+ in div_ [] $
+ [ maybe (text "..") (either err viewSchema) model.schema,
+ maybe (text "..") (either err viewPosts) model.posts,
+ maybe (text "..") (either err (viewForm input)) model.schema,
+ viewInput input
+ ]
err :: String -> View Action
err = text . toMisoString . ("err! " <>)
@@ -189,6 +185,16 @@ viewSchema schema =
)
<$> (M.toList properties)
+viewForm :: A.Value -> Schema -> View Action
+viewForm input =
+ fmap (either FormChanged FormSubmitted)
+ . flip F.runForm input
+ . schemaForm
+
+viewInput :: A.Value -> View Action
+viewInput input =
+ pre_ [] [text (toMisoString (A.encode input))]
+
schemaForm :: Schema -> F.Form A.Value A.Value
schemaForm schema =
fmap mergeJson . sequence $