refactor pages
This commit is contained in:
43
frontend/app/Page.hs
Normal file
43
frontend/app/Page.hs
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user