Update part3
This commit is contained in:
@@ -18,6 +18,23 @@ initialModel =
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- UPDATE --
|
||||||
|
|
||||||
|
|
||||||
|
update msg model =
|
||||||
|
if msg.operation == "SELECT_TAG" then
|
||||||
|
{- TODO Return `model` with the `selectedTag` field set to `msg.data`
|
||||||
|
|
||||||
|
HINT: Record update syntax looks like this:
|
||||||
|
|
||||||
|
{ model | foo = bar }
|
||||||
|
-}
|
||||||
|
model
|
||||||
|
else
|
||||||
|
model
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- VIEW --
|
-- VIEW --
|
||||||
|
|
||||||
|
|
||||||
@@ -47,48 +64,53 @@ viewBanner =
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
viewTags model =
|
{-| TODO Give this function a new first argument called `selectedTag`, like so:
|
||||||
div [ class "tag-list" ] (List.map viewTag model.tags)
|
|
||||||
|
|
||||||
|
BEFORE:
|
||||||
|
|
||||||
|
viewTag tagName =
|
||||||
|
|
||||||
|
AFTER:
|
||||||
|
|
||||||
|
viewTag selectedTag tagName =
|
||||||
|
|
||||||
|
HINT: This will cause a compiler error. See where the error message takes you!
|
||||||
|
|
||||||
|
-}
|
||||||
viewTag tagName =
|
viewTag tagName =
|
||||||
let
|
let
|
||||||
classname =
|
classname =
|
||||||
{- TODO Change this if-expression to be more useful:
|
{- TODO Set the classname to "tag-pill tag-selected" only
|
||||||
|
when tagName == selectedTag
|
||||||
if tagName == selectedTag then
|
|
||||||
|
|
||||||
Then change viewTag to take selectedTag as its first argument:
|
|
||||||
|
|
||||||
viewTag selectedTag tagName =
|
|
||||||
-}
|
-}
|
||||||
if tagName == tagName then
|
if False then
|
||||||
"tag-pill tag-default"
|
|
||||||
else
|
|
||||||
"tag-pill tag-selected"
|
"tag-pill tag-selected"
|
||||||
|
else
|
||||||
|
"tag-pill tag-default"
|
||||||
in
|
in
|
||||||
|
{- TODO add an onClick handler here which selects `tagName`
|
||||||
|
|
||||||
|
HINT: Take look at `update` above, to check what it expects `msg`
|
||||||
|
to be. It will look something like this:
|
||||||
|
|
||||||
button
|
button
|
||||||
[ class classname
|
[ class classname
|
||||||
|
, onClick { operation = "SOMETHING", data = "tag name goes here" }
|
||||||
{- TODO add an onClick handler here which selects the given tag.
|
]
|
||||||
|
[ text tagName ]
|
||||||
HINT: This will require coordination with the update function!
|
|
||||||
-}
|
-}
|
||||||
|
button
|
||||||
|
[ class classname
|
||||||
]
|
]
|
||||||
[ text tagName ]
|
[ text tagName ]
|
||||||
|
|
||||||
|
|
||||||
|
{-| HINT: Take a look at how initialModel is defined at the top of this file.
|
||||||
|
-}
|
||||||
|
viewTags model =
|
||||||
|
div [ class "tag-list" ]
|
||||||
|
(List.map (\tag -> viewTag tag) model.tags)
|
||||||
|
|
||||||
|
|
||||||
viewFeed feed =
|
viewFeed feed =
|
||||||
div [ class "feed-toggle" ] [ text "(We’ll display some articles here later.)" ]
|
div [ class "feed-toggle" ] [ text "(We’ll display some articles here later.)" ]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- UPDATE --
|
|
||||||
|
|
||||||
|
|
||||||
update msg model =
|
|
||||||
if msg.operation == "SELECT_TAG" then
|
|
||||||
-- TODO Return `model` with the `selectedTag` field set to `msg.data`
|
|
||||||
model
|
|
||||||
else
|
|
||||||
model
|
|
||||||
|
|||||||
Reference in New Issue
Block a user