Last active
November 29, 2015 14:37
-
-
Save ccapndave/8eb1c90fcf606f9f895f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module App (init, update, view, Action(StudentAction)) where | |
import Effects | |
import Html exposing (Html, text) | |
import Debug | |
import Student | |
import Components.StudentsPage | |
type Page | |
= StudentsPage | |
type alias Model = | |
{ page : Page | |
, studentModel : Student.Model | |
} | |
type Action | |
= SetPage Page | |
-- Child pages | |
| StudentsPageAction Components.StudentsPage.Action | |
init : ( Model, Effects.Effects a ) | |
init = ( | |
{ page = StudentsPage | |
, studentModel = Student.init |> fst | |
} | |
, Effects.none | |
) | |
update : Action -> Model -> (Model, Effects.Effects c) | |
update action model = | |
let | |
_ = Debug.log "action" action | |
_ = Debug.log "model" model | |
-- Certain actions get translated into page transitions | |
action = pageChangeActionMapper action | |
in | |
case action of | |
SetPage page -> | |
( { model | page = page } | |
, Effects.none | |
) | |
-- Child actions | |
StudentsPageAction studentsPageAction -> | |
let | |
(childModel, childEffects) = StudentsPage.update studentsPageAction model.studentModel | |
in | |
( { model | studentModel = childModel } | |
, childEffects) | |
{- | |
Certain Actions result in a page change at this level. Therefore the actions are intercepted here | |
and translated to a new page if appropriate. | |
-} | |
pageChangeActionMapper : Action -> Action | |
pageChangeActionMapper action = | |
case action of | |
StudentsPageAction (Components.StudentsPage.StudentSelected student) -> | |
SetPage <| StudentPage student | |
_ -> | |
action | |
view : Signal.Address Action -> Model -> Html | |
view address model = | |
case model.page of | |
StudentsPage -> | |
Components.StudentsPage.view (Signal.forwardTo address StudentsPageAction) model.studentModel | |
_ -> | |
Debug.crash "TODO" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Components.StudentsPage (view, Action(StudentSelected)) where | |
import Html exposing (..) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (..) | |
import Components.UI.StudentFace | |
import Student | |
type Action | |
= StudentSelected Student.Student | |
view : Signal.Address Action -> Student.Model -> Html | |
view address model = | |
div | |
[ class "students-page page" ] | |
[ header [] | |
[ h1 [] | |
[ text "Click on your photo" ] | |
] | |
, ul | |
[ class "student-list" ] | |
(List.map (renderStudent address) model.students) | |
, a | |
[ class "btn btn-green pull-right" ] | |
[ i | |
[ class "fa fa-cog" ] | |
[] | |
] | |
] | |
renderStudent : Signal.Address Action -> Student.Student -> Html | |
renderStudent address student = | |
li [] | |
[ a | |
[ onClick address (StudentSelected student) ] | |
[ Components.UI.StudentFace.view student False ] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment