From 412ddaa55f818cb2758e422d82312950ae916ce8 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 14 Aug 2018 01:58:49 -0400 Subject: [PATCH] Solution to intro/part4 --- intro/part4/src/Main.elm | 44 +++++++++++++++------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/intro/part4/src/Main.elm b/intro/part4/src/Main.elm index 0f7f04c..450c387 100644 --- a/intro/part4/src/Main.elm +++ b/intro/part4/src/Main.elm @@ -14,27 +14,20 @@ import Html.Events exposing (onClick) type alias Model = { tags : List String , selectedTag : String - - {- 👉 TODO: change this `allArticles` annotation to the following: - - allArticles : List Article - - - 💡 HINT: You'll need to move the existing annotation to a `type alias`. - -} - , allArticles : - List - { title : String - , description : String - , body : String - , tags : List String - , slug : String - } + , allArticles : List Article } -{-| 👉 TODO: Replace this comment with a type annotation for `initialModel` --} +type alias Article = + { title : String + , description : String + , body : String + , tags : List String + , slug : String + } + + +initialModel : Model initialModel = { tags = Article.tags , selectedTag = "elm" @@ -52,8 +45,7 @@ type alias Msg = } -{-| 👉 TODO: Replace this comment with a type annotation for `update` --} +update : Msg -> Model -> Model update msg model = if msg.description == "ClickedTag" then { model | selectedTag = msg.data } @@ -66,8 +58,7 @@ update msg model = -- VIEW -{-| 👉 TODO: Replace this comment with a type annotation for `view` --} +view : Model -> Html Msg view model = let articles = @@ -93,8 +84,7 @@ view model = ] -{-| 👉 TODO: Replace this comment with a type annotation for `view` --} +viewArticle : Article -> Html Msg viewArticle article = div [ class "article-preview" ] [ h1 [] [ text article.title ] @@ -103,8 +93,7 @@ viewArticle article = ] -{-| 👉 TODO: Replace this comment with a type annotation for `viewBanner` --} +viewBanner : Html Msg viewBanner = div [ class "banner" ] [ div [ class "container" ] @@ -114,8 +103,7 @@ viewBanner = ] -{-| 👉 TODO: Replace this comment with a type annotation for `viewTag` --} +viewTag : String -> String -> Html Msg viewTag selectedTagName tagName = let otherClass =