aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/app/Page/NewCollection.hs
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app/Page/NewCollection.hs')
-rw-r--r--frontend/app/Page/NewCollection.hs32
1 files changed, 14 insertions, 18 deletions
diff --git a/frontend/app/Page/NewCollection.hs b/frontend/app/Page/NewCollection.hs
index dbc448b..12b9cf1 100644
--- a/frontend/app/Page/NewCollection.hs
+++ b/frontend/app/Page/NewCollection.hs
@@ -25,33 +25,29 @@ initialModel :: JSM (Either String Model)
initialModel = do
pure (Right (Model {input = ""}))
-data Action
- = NoOp
- | FormChanged T.Text
- | FormSubmitted T.Text
- | CollectionCreated (Either String ())
- deriving (Eq, Show)
+newtype Action = Action (Model -> (Effect Action Model, [Eff]))
-updateModel :: Action -> Model -> (Effect Action Model, [Eff])
-updateModel NoOp m = (noEff m, [])
-updateModel (FormChanged input) m = (noEff m {input}, [])
-updateModel (FormSubmitted collection) m =
- ( m <# do
- CollectionCreated <$> createCollection (T.unpack collection),
- []
- )
-updateModel (CollectionCreated (Left err)) m =
+update__formChanged :: T.Text -> Action
+update__formChanged input = Action $ \m -> (noEff m {input}, [])
+
+update__formSubmitted :: T.Text -> Action
+update__formSubmitted collection = Action $ \m ->
( m <# do
- pure NoOp <* consoleLog (toMisoString err),
+ update__collectionCreated <$> createCollection (T.unpack collection),
[]
)
-updateModel (CollectionCreated (Right _)) m = (noEff m, [E.ReloadCollections])
+
+update__collectionCreated :: Either String () -> Action
+update__collectionCreated _ = Action $ \m -> (noEff m, [E.ReloadCollections])
+
+updateModel :: Action -> Model -> (Effect Action Model, [Eff])
+updateModel (Action f) m = f m
viewModel :: Model -> View Action
viewModel m = do
div_ [] $
[ h3_ [] [text "new collection"],
- either FormChanged FormSubmitted
+ either update__formChanged update__formSubmitted
<$> F.runForm collectionForm m.input,
pre_ [] [text (toMisoString (A.encode m.input))],
pre_ [] [text (toMisoString (A.encode (collectionForm.fill m.input)))]