TODOify part10

This commit is contained in:
Richard Feldman
2016-09-04 23:43:46 -07:00
parent 378dd1f136
commit 56cbcaafea

View File

@@ -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 -> Html Msg
view model = view model =
div [ class "content" ] div [ class "content" ]
@@ -79,7 +122,7 @@ view model =
[ h1 [] [ text "ElmHub" ] [ h1 [] [ text "ElmHub" ]
, span [ class "tagline" ] [ text "Like GitHub, but for Elm things." ] , 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 ] [] , input [ class "search-query", onInput SetQuery, defaultValue model.query ] []
, button [ class "search-button", onClick Search ] [ text "Search" ] , button [ class "search-button", onClick Search ] [ text "Search" ]
, viewErrorMessage model.errorMessage , 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 type OptionsMsg
= SetSort String = SetSort String
| SetOrder String | SetOrder String