From 5f75c624b3f3e664cc0df10b384e5e49aeadc91b Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Sun, 4 Sep 2016 23:27:11 -0700 Subject: [PATCH] Add some stuff to part10 --- part10/ElmHub.elm | 24 +++++++++++++++ part10/SearchOptions.elm | 63 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 part10/SearchOptions.elm diff --git a/part10/ElmHub.elm b/part10/ElmHub.elm index 6a47dcc..9f3d03e 100644 --- a/part10/ElmHub.elm +++ b/part10/ElmHub.elm @@ -3,9 +3,11 @@ module ElmHub exposing (..) import Html exposing (..) import Html.Attributes exposing (class, target, href, property, defaultValue) import Html.Events exposing (..) +import Html.App as Html import Auth import Json.Decode exposing (Decoder) import Json.Decode.Pipeline exposing (..) +import SearchOptions getQueryString : String -> String @@ -35,6 +37,7 @@ type alias Model = { query : String , results : List SearchResult , errorMessage : Maybe String + , searchOptions : SearchOptions.Model } @@ -50,9 +53,16 @@ initialModel = { query = "tutorial" , results = [] , errorMessage = Nothing + , searchOptions = SearchOptions.initialModel } +viewAdvancedSearch : Model -> Html Msg +viewAdvancedSearch model = + SearchOptions.view model.searchOptions + |> Html.map SearchOptionsMsg + + view : Model -> Html Msg view model = div [ class "content" ] @@ -90,6 +100,7 @@ viewSearchResult result = type Msg = Search + | SearchOptionsMsg SearchOptions.Msg | SetQuery String | DeleteById Int | HandleSearchResponse (List SearchResult) @@ -103,6 +114,19 @@ update searchFeed msg model = Search -> ( model, searchFeed (getQueryString model.query) ) + SearchOptionsMsg advancedSearchMsg -> + let + newSearchOptions = + -- TODO call SearchOptions.update + -- to determine our new searchOptions value. + -- + -- model.searchOptions + SearchOptions.update advancedSearchMsg model.searchOptions + in + -- TODO update our model to use the newSearchOptions value above. + -- ( model, Cmd.none ) + ( { model | searchOptions = newSearchOptions }, Cmd.none ) + SetQuery query -> ( { model | query = query }, Cmd.none ) diff --git a/part10/SearchOptions.elm b/part10/SearchOptions.elm new file mode 100644 index 0000000..e862cc0 --- /dev/null +++ b/part10/SearchOptions.elm @@ -0,0 +1,63 @@ +module SearchOptions exposing (..) + +import Html exposing (..) +import Html.Attributes exposing (class, checked, type', defaultValue) +import Html.Events exposing (..) +import String + + +view : Model -> Html Msg +view model = + div [] + [ input [ type' "text", defaultValue model.sort, onInput SetSort ] [] + , input [ type' "text", defaultValue model.order, onInput SetOrder ] [] + , input [ type' "text", defaultValue (String.join " " model.searchIn) ] [] + , input [ type' "checkbox", checked model.includeForks ] [] + , input [ type' "text", defaultValue model.userFilter, onInput SetUserFilter ] [] + ] + + +type alias Model = + { sort : String + , order : String + , searchIn : List String + , includeForks : Bool + , userFilter : String + } + + +type Msg + = SetSort String + | SetOrder String + | SetSearchIn (List String) + | SetIncludeForks Bool + | SetUserFilter String + + +update : Msg -> Model -> Model +update msg model = + case msg of + SetSort sort -> + { model | sort = sort } + + SetOrder order -> + { model | order = order } + + SetSearchIn searchIn -> + { model | searchIn = searchIn } + + SetIncludeForks includeForks -> + { model | includeForks = includeForks } + + SetUserFilter userFilter -> + { model | userFilter = userFilter } + + +initialModel : Model +initialModel = + { sort = "" + , order = "" + , searchIn = [] + , includeForks = True + , userFilter = "" + }