blob: e1c841598ae0d5ef63cb6b212454bbd4c29fd76c (
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
module Page
( Page (..),
Action,
initialPage,
updatePage,
viewPage,
)
where
import Collection
import Control.Monad.Catch (SomeException)
import Data.Bifunctor
import Data.Default
import Data.Function
import Effect (Eff)
import Miso
import Miso.String (fromMisoString)
import Page.EditValue qualified as EditValue
import Page.ListCollection qualified as ListCollection
import Page.NewCollection qualified as NewCollection
import Route (Route)
import Route qualified as Route
data Page
= Home
| ListCollection ListCollection.Model
| EditValue EditValue.Model
| NewCollection NewCollection.Model
deriving (Show, Eq)
newtype Action = Action (Page -> (Effect Action Page, [Eff]))
instance Default Page where
def = Home
initialPage :: Route -> JSM (Either SomeException Page)
initialPage Route.Home = pure (Right Home)
initialPage (Route.ListCollection c) =
fmap ListCollection <$> ListCollection.initialModel (Collection (fromMisoString c))
initialPage (Route.EditValue c f) =
fmap EditValue <$> EditValue.initialModel (CollectionItem (Collection (fromMisoString c)) (fromMisoString f))
initialPage Route.NewCollection =
fmap NewCollection <$> NewCollection.initialModel
update__handleListCollection :: ListCollection.Action -> Action
update__handleListCollection action = Action $ \case
ListCollection m ->
ListCollection.updateModel action m
& first (bimap update__handleListCollection ListCollection)
p -> (noEff p, [])
update__handleEditValue :: EditValue.Action -> Action
update__handleEditValue action = Action $ \case
EditValue m ->
EditValue.updateModel action m
& first (bimap update__handleEditValue EditValue)
p -> (noEff p, [])
update__handleNewCollection :: NewCollection.Action -> Action
update__handleNewCollection action = Action $ \case
NewCollection m ->
NewCollection.updateModel action m
& first (bimap update__handleNewCollection NewCollection)
p -> (noEff p, [])
updatePage :: Action -> Page -> (Effect Action Page, [Eff])
updatePage (Action f) m = f m
viewPage :: Page -> View Action
viewPage Home = text "home"
viewPage (ListCollection m) = update__handleListCollection <$> ListCollection.viewModel m
viewPage (EditValue m) = update__handleEditValue <$> EditValue.viewModel m
viewPage (NewCollection m) = update__handleNewCollection <$> NewCollection.viewModel m
|