diff options
| author | Christine Dodrill <me@christine.website> | 2016-12-13 23:11:20 -0800 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2016-12-13 23:11:20 -0800 |
| commit | 060a7c913a6eb1f30052504678e04fccc404b930 (patch) | |
| tree | a7ae1eae7d377888c23976e32a4d002b9715c6f2 /frontend/src/Layout.purs | |
| download | xesite-060a7c913a6eb1f30052504678e04fccc404b930.tar.xz xesite-060a7c913a6eb1f30052504678e04fccc404b930.zip | |
initial commit, get frontend code in
Diffstat (limited to 'frontend/src/Layout.purs')
| -rw-r--r-- | frontend/src/Layout.purs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/frontend/src/Layout.purs b/frontend/src/Layout.purs new file mode 100644 index 0000000..0507aef --- /dev/null +++ b/frontend/src/Layout.purs @@ -0,0 +1,61 @@ +module App.Layout where + +import App.BlogIndex as BlogIndex +import App.Counter as Counter +import App.Routes (Route(..)) +import DOM (DOM) +import Network.HTTP.Affjax (AJAX) +import Prelude (($), (#), map, pure) +import Pux (EffModel, noEffects, mapEffects, mapState) +import Pux.Html (Html, div, h1, nav, text) +import Pux.Html.Attributes (className, id_, role) +import Pux.Router (link) + +data Action + = Child (Counter.Action) + | BIChild (BlogIndex.Action) + | PageView Route + +type State = + { route :: Route + , count :: Counter.State + , bistate :: BlogIndex.State } + +init :: State +init = + { route: NotFound + , count: Counter.init + , bistate: BlogIndex.init } + +update :: Action -> State -> EffModel State Action (ajax :: AJAX, dom :: DOM) +update (PageView route) state = noEffects $ state { route = route } +update (BIChild action) state = BlogIndex.update action state.bistate + # mapState (state { bistate = _ }) + # mapEffects BIChild +update (Child action) state = noEffects $ state { count = Counter.update action state.count } + +view :: State -> Html Action +view state = + div + [] + [ navbar state + , div + [ className "container" ] + [ page state.route state ] + ] + +navbar :: State -> Html Action +navbar state = + nav + [ className "light-blue lighten-1", role "navigation" ] + [ div + [ className "nav-wrapper container" ] + [ link "/" [ className "brand-logo", id_ "logo-container" ] [ text "Christine Dodrill" ] ] + ] + +page :: Route -> State -> Html Action +page NotFound _ = h1 [] [ text "not found" ] +page Home state = map Child $ Counter.view state.count +page Resume state = h1 [] [ text "Christine Dodrill" ] +page BlogIndex state = map BIChild $ BlogIndex.view state.bistate +page _ _ = h1 [] [ text "not implemented yet" ] |
