aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/app/Page/NewCollection.hs
blob: b105689fcfc962728cbaa82a154334a274f68e0a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module Page.NewCollection
  ( Model,
    initialModel,
    Action,
    updateModel,
    viewModel,
  )
where

import Data.Text qualified as T
import Form qualified as F
import Miso

data Model = Model
  { input :: T.Text
  }
  deriving (Show, Eq)

initialModel :: JSM (Either String Model)
initialModel = do
  pure (Right (Model {input = ""}))

data Action
  = NoOp
  | FormChanged T.Text
  | FormSubmitted T.Text
  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

viewModel :: Model -> View Action
viewModel m = do
  div_ [] $
    [ h3_ [] [text "new collection"],
      either FormChanged FormSubmitted
        <$> F.runForm collectionForm m.input
    ]

collectionForm :: F.Form T.Text T.Text
collectionForm =
  F.input "name"