Add some stuff to part10
This commit is contained in:
@@ -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 )
|
||||
|
||||
|
||||
63
part10/SearchOptions.elm
Normal file
63
part10/SearchOptions.elm
Normal file
@@ -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 = ""
|
||||
}
|
||||
Reference in New Issue
Block a user