aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/app/Page/NewCollection.hs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-10-11 23:30:56 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-10-11 23:30:56 +0200
commit80a6150610182eefa0deb1f0932d3b780456ca09 (patch)
tree4471a8ffecfc527d6b9c2a5c48e445e7a4d6a74f /frontend/app/Page/NewCollection.hs
parent2e0cf98254976e443ea7f693961fc105ed6cf563 (diff)
use backend REST library for frontend
Diffstat (limited to 'frontend/app/Page/NewCollection.hs')
-rw-r--r--frontend/app/Page/NewCollection.hs19
1 files changed, 10 insertions, 9 deletions
diff --git a/frontend/app/Page/NewCollection.hs b/frontend/app/Page/NewCollection.hs
index 12b9cf1..a15d4a7 100644
--- a/frontend/app/Page/NewCollection.hs
+++ b/frontend/app/Page/NewCollection.hs
@@ -7,37 +7,38 @@ module Page.NewCollection
)
where
-import Api
+import ACMS.API.REST qualified as API.REST
+import Control.Monad.Catch (SomeException, try)
import Data.Aeson qualified as A
import Data.Text qualified as T
import Effect (Eff)
import Effect qualified as E
import Form qualified as F
import Miso
-import Miso.String (toMisoString)
+import Miso.String (MisoString, toMisoString)
data Model = Model
- { input :: T.Text
+ { input :: MisoString
}
deriving (Show, Eq)
-initialModel :: JSM (Either String Model)
+initialModel :: JSM (Either SomeException Model)
initialModel = do
pure (Right (Model {input = ""}))
newtype Action = Action (Model -> (Effect Action Model, [Eff]))
-update__formChanged :: T.Text -> Action
+update__formChanged :: MisoString -> Action
update__formChanged input = Action $ \m -> (noEff m {input}, [])
-update__formSubmitted :: T.Text -> Action
+update__formSubmitted :: MisoString -> Action
update__formSubmitted collection = Action $ \m ->
( m <# do
- update__collectionCreated <$> createCollection (T.unpack collection),
+ update__collectionCreated <$> try (API.REST.createCollection collection),
[]
)
-update__collectionCreated :: Either String () -> Action
+update__collectionCreated :: Either SomeException () -> Action
update__collectionCreated _ = Action $ \m -> (noEff m, [E.ReloadCollections])
updateModel :: Action -> Model -> (Effect Action Model, [Eff])
@@ -53,6 +54,6 @@ viewModel m = do
pre_ [] [text (toMisoString (A.encode (collectionForm.fill m.input)))]
]
-collectionForm :: F.Form T.Text T.Text
+collectionForm :: F.Form MisoString MisoString
collectionForm =
F.input "name"