From 56cbcaafea78c6abea1dbf4533eda6cc955f20a3 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 4 Sep 2016 23:43:46 -0700 Subject: [PATCH] TODOify part10 --- part10/ElmHub.elm | 88 +++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/part10/ElmHub.elm b/part10/ElmHub.elm index e1797be..a4be55d 100644 --- a/part10/ElmHub.elm +++ b/part10/ElmHub.elm @@ -72,6 +72,49 @@ initialModel = } +type Msg + = Search + -- TODO add a constructor for Options OptionsMsg + | SetQuery String + | DeleteById Int + | HandleSearchResponse (List SearchResult) + | HandleSearchError (Maybe String) + | DoNothing + + +update : (String -> Cmd Msg) -> Msg -> Model -> ( Model, Cmd Msg ) +update searchFeed msg model = + case msg of + -- TODO Add a branch for Options which updates model.options + -- + -- HINT: calling updateOptions will save a lot of time here! + Search -> + ( model, searchFeed (getQueryString model.query) ) + + SetQuery query -> + ( { model | query = query }, Cmd.none ) + + HandleSearchResponse results -> + ( { model | results = results }, Cmd.none ) + + HandleSearchError error -> + ( { model | errorMessage = error }, Cmd.none ) + + DeleteById idToHide -> + let + newResults = + model.results + |> List.filter (\{ id } -> id /= idToHide) + + newModel = + { model | results = newResults } + in + ( newModel, Cmd.none ) + + DoNothing -> + ( model, Cmd.none ) + + view : Model -> Html Msg view model = div [ class "content" ] @@ -79,7 +122,7 @@ view model = [ h1 [] [ text "ElmHub" ] , span [ class "tagline" ] [ text "Like GitHub, but for Elm things." ] ] - , Html.map Options (viewOptions model.options) + -- TODO call viewOptions here. Use Html.map to avoid a type mismatch! , input [ class "search-query", onInput SetQuery, defaultValue model.query ] [] , button [ class "search-button", onClick Search ] [ text "Search" ] , viewErrorMessage model.errorMessage @@ -108,49 +151,6 @@ viewSearchResult result = ] -type Msg - = Search - | Options OptionsMsg - | SetQuery String - | DeleteById Int - | HandleSearchResponse (List SearchResult) - | HandleSearchError (Maybe String) - | DoNothing - - -update : (String -> Cmd Msg) -> Msg -> Model -> ( Model, Cmd Msg ) -update searchFeed msg model = - case msg of - Search -> - ( model, searchFeed (getQueryString model.query) ) - - Options optionsMsg -> - ( { model | options = updateOptions optionsMsg model.options }, Cmd.none ) - - SetQuery query -> - ( { model | query = query }, Cmd.none ) - - HandleSearchResponse results -> - ( { model | results = results }, Cmd.none ) - - HandleSearchError error -> - ( { model | errorMessage = error }, Cmd.none ) - - DeleteById idToHide -> - let - newResults = - model.results - |> List.filter (\{ id } -> id /= idToHide) - - newModel = - { model | results = newResults } - in - ( newModel, Cmd.none ) - - DoNothing -> - ( model, Cmd.none ) - - type OptionsMsg = SetSort String | SetOrder String