aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/app/Page.hs
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/app/Page.hs')
-rw-r--r--frontend/app/Page.hs48
1 files changed, 27 insertions, 21 deletions
diff --git a/frontend/app/Page.hs b/frontend/app/Page.hs
index 7c200c8..3218ae6 100644
--- a/frontend/app/Page.hs
+++ b/frontend/app/Page.hs
@@ -10,13 +10,13 @@ where
import Data.Bifunctor
import Data.Default
import Data.Function
+import Effect (Eff)
import Miso
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
-import Effect (Eff)
data Page
= Home
@@ -25,11 +25,7 @@ data Page
| NewCollection NewCollection.Model
deriving (Show, Eq)
-data Action
- = HandleListCollection ListCollection.Action
- | HandleEditValue EditValue.Action
- | HandleNewCollection NewCollection.Action
- deriving (Show, Eq)
+newtype Action = Action (Page -> (Effect Action Page, [Eff]))
instance Default Page where
def = Home
@@ -43,22 +39,32 @@ initialPage (Route.EditValue c 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 (HandleListCollection action) (ListCollection m) =
- ListCollection.updateModel action m
- & first (bimap HandleListCollection ListCollection)
-updatePage (HandleListCollection _) p = (noEff p, [])
-updatePage (HandleEditValue action) (EditValue m) =
- EditValue.updateModel action m
- & first (bimap HandleEditValue EditValue)
-updatePage (HandleEditValue _) p = (noEff p, [])
-updatePage (HandleNewCollection action) (NewCollection m) =
- NewCollection.updateModel action m
- & first (bimap HandleNewCollection NewCollection)
-updatePage (HandleNewCollection _) p = (noEff p, [])
+updatePage (Action f) m = f m
viewPage :: Page -> View Action
viewPage Home = text "home"
-viewPage (ListCollection m) = HandleListCollection <$> ListCollection.viewModel m
-viewPage (EditValue m) = HandleEditValue <$> EditValue.viewModel m
-viewPage (NewCollection m) = HandleNewCollection <$> NewCollection.viewModel m
+viewPage (ListCollection m) = update__handleListCollection <$> ListCollection.viewModel m
+viewPage (EditValue m) = update__handleEditValue <$> EditValue.viewModel m
+viewPage (NewCollection m) = update__handleNewCollection <$> NewCollection.viewModel m