From 80a6150610182eefa0deb1f0932d3b780456ca09 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Fri, 11 Oct 2024 23:30:56 +0200 Subject: use backend REST library for frontend --- frontend/app/Page/NewCollection.hs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'frontend/app/Page/NewCollection.hs') 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" -- cgit v1.2.3