aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/app/Page.hs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-06-04 14:36:26 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-06-04 14:46:41 +0200
commited753b04104b27a9b258f174a501e2ae058b41ee (patch)
treeddddddddbe2e92e13140926eea7193f093383754 /frontend/app/Page.hs
parent03b019ca96ceb83113a5ea34f4b48b039c56f02d (diff)
refactor pages
Diffstat (limited to 'frontend/app/Page.hs')
-rw-r--r--frontend/app/Page.hs43
1 files changed, 43 insertions, 0 deletions
diff --git a/frontend/app/Page.hs b/frontend/app/Page.hs
new file mode 100644
index 0000000..84a551f
--- /dev/null
+++ b/frontend/app/Page.hs
@@ -0,0 +1,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