aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/app/Page/EditValue.hs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-06-14 20:56:07 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-10-11 20:38:29 +0200
commit2e0cf98254976e443ea7f693961fc105ed6cf563 (patch)
tree271c8a73c14b6fffe6504494d61f68d7fda5e59e /frontend/app/Page/EditValue.hs
parent07a2f177f440526a374ef3844a1c37ba38939861 (diff)
refactor actions
Diffstat (limited to 'frontend/app/Page/EditValue.hs')
-rw-r--r--frontend/app/Page/EditValue.hs27
1 files changed, 14 insertions, 13 deletions
diff --git a/frontend/app/Page/EditValue.hs b/frontend/app/Page/EditValue.hs
index 43c6f17..cdb1dd0 100644
--- a/frontend/app/Page/EditValue.hs
+++ b/frontend/app/Page/EditValue.hs
@@ -12,10 +12,10 @@ import Data.Aeson qualified as A
import Data.Aeson.KeyMap qualified as AM
import Data.ByteString.Lazy.UTF8 as LB
import Data.Maybe
+import Effect (Eff)
import Form qualified as F
import Miso
import Miso.String (toMisoString)
-import Effect (Eff)
import Schema
data Model = Model
@@ -35,19 +35,20 @@ initialModel collection fileName = do
input <- input'
pure $ Model {..}
-data Action
- = NoOp
- | FormChanged A.Value
- | FormSubmitted A.Value
- | EntityWritten (Either String ())
- deriving (Eq, Show)
+newtype Action = Action (Model -> (Effect Action Model, [Eff]))
+
+update__formChanged :: A.Value -> Action
+update__formChanged (Just -> input) = Action $ \m -> (noEff m {input}, [])
+
+update__formSubmitted :: A.Value -> Action
+update__formSubmitted output = Action $ \m ->
+ (m <# do update__entityWritten <$> updatePost m.fileName output, [])
+
+update__entityWritten :: Either String () -> Action
+update__entityWritten _ = Action $ \m -> (noEff m, [])
updateModel :: Action -> Model -> (Effect Action Model, [Eff])
-updateModel NoOp m = (noEff m, [])
-updateModel (FormChanged (Just -> input)) m = (noEff m {input}, [])
-updateModel (FormSubmitted output) m =
- (m <# do EntityWritten <$> updatePost m.fileName output, [])
-updateModel (EntityWritten _) m = (noEff m, [])
+updateModel (Action f) m = f m
viewModel :: Model -> View Action
viewModel m = do
@@ -60,7 +61,7 @@ viewModel m = do
viewForm :: A.Value -> Schema -> View Action
viewForm input =
- fmap (either FormChanged FormSubmitted)
+ fmap (either update__formChanged update__formSubmitted)
. flip F.runForm input
. schemaForm