diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-06-07 16:14:52 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-06-07 17:06:17 +0200 |
commit | 8a34cc822c2c508472fe29ab2be1b74ba06e59e6 (patch) | |
tree | 74a67b93a76addabdb0fcf9e9479f4c6f7b4d113 /frontend/app/Page/NewCollection.hs | |
parent | 79dd6af899fbaf7c413d7fd864f5716cbdf544e5 (diff) |
add collections
Diffstat (limited to 'frontend/app/Page/NewCollection.hs')
-rw-r--r-- | frontend/app/Page/NewCollection.hs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/frontend/app/Page/NewCollection.hs b/frontend/app/Page/NewCollection.hs index b105689..282d36e 100644 --- a/frontend/app/Page/NewCollection.hs +++ b/frontend/app/Page/NewCollection.hs @@ -7,9 +7,12 @@ module Page.NewCollection ) where +import Api +import Data.Aeson qualified as A import Data.Text qualified as T import Form qualified as F import Miso +import Miso.String (toMisoString) data Model = Model { input :: T.Text @@ -24,19 +27,29 @@ data Action = NoOp | FormChanged T.Text | FormSubmitted T.Text + | CollectionCreated (Either String ()) deriving (Eq, Show) updateModel :: Action -> Model -> Effect Action Model updateModel NoOp m = noEff m updateModel (FormChanged input) m = noEff m {input} -updateModel (FormSubmitted _) m = noEff m +updateModel (FormSubmitted collection) m = + m <# do + CollectionCreated <$> createCollection (T.unpack collection) +updateModel (CollectionCreated (Left err)) m = + m <# do + pure NoOp <* consoleLog (toMisoString err) +-- TODO reload collections in main app +updateModel (CollectionCreated (Right _)) m = noEff m viewModel :: Model -> View Action viewModel m = do div_ [] $ [ h3_ [] [text "new collection"], either FormChanged FormSubmitted - <$> F.runForm collectionForm m.input + <$> F.runForm collectionForm m.input, + pre_ [] [text (toMisoString (A.encode m.input))], + pre_ [] [text (toMisoString (A.encode (collectionForm.fill m.input)))] ] collectionForm :: F.Form T.Text T.Text |