aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/app/Page.hs
blob: 84a551f075de7dabe3139197453e9674dcc0641f (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
module Page
  ( Page (..),
    Action,
    initialPage,
    updatePage,
    viewPage,
  )
where

import Data.Bifunctor
import Data.Default
import Data.Function
import Miso
import Page.ListCollection qualified as ListCollection
import Route (Route)
import Route qualified as Route

data Page
  = Home
  | ListCollection ListCollection.Model
  deriving (Show, Eq)

instance Default Page where
  def = Home

data Action
  = HandleListCollection ListCollection.Action
  deriving (Show, Eq)

initialPage :: Route -> JSM (Either String Page)
initialPage Route.Home = pure (Right Home)
initialPage (Route.ListCollection c) =
  fmap ListCollection <$> ListCollection.initialModel c

updatePage :: Action -> Page -> Effect Action Page
updatePage (HandleListCollection action) (ListCollection m) =
  ListCollection.updateModel action m
    & bimap HandleListCollection ListCollection
updatePage (HandleListCollection _) p = noEff p

viewPage :: Page -> View Action
viewPage Home = text "home"
viewPage (ListCollection m) = HandleListCollection <$> ListCollection.viewModel m