Files
elm-0.19-workshop/part3/src/Page/Home.elm
Richard Feldman bf20622319 wip
2018-08-05 04:07:11 -04:00

82 lines
1.8 KiB
Elm
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
module Page.Home exposing (initialModel, update, view)
{-| The homepage. You can get here via either the / or /#/ routes.
-}
import Html exposing (..)
import Html.Attributes exposing (attribute, class, classList, href, id, placeholder)
import Html.Events exposing (onClick)
-- MODEL --
initialModel =
{ tags = [ "foo", "bar", "baz", "dragons", "tag name goes here" ]
, selectedTag = ""
}
-- UPDATE --
update msg model =
if msg.operation == "SELECT_TAG" then
{ model | selectedTag = msg.data }
else
model
-- VIEW --
view model =
div [ class "home-page" ]
[ viewBanner
, div [ class "container page" ]
[ div [ class "row" ]
[ div [ class "col-md-9" ] [ viewFeed [] ]
, div [ class "col-md-3" ]
[ div [ class "sidebar" ]
[ p [] [ text "Popular Tags" ]
, viewTags model
]
]
]
]
]
viewBanner =
div [ class "banner" ]
[ div [ class "container" ]
[ h1 [ class "logo-font" ] [ text "conduit" ]
, p [] [ text "A place to share your knowledge." ]
]
]
viewTag selectedTagName tagName =
let
classname =
if tagName == selectedTagName then
"tag-pill tag-selected"
else
"tag-pill tag-default"
in
button
[ class classname
, onClick { operation = "SELECT_TAG", data = tagName }
]
[ text tagName ]
viewTags model =
div [ class "tag-list" ] (List.map (viewTag model.selectedTag) model.tags)
viewFeed feed =
div [ class "feed-toggle" ] [ text "(Well display some articles here later.)" ]