Add some stuff to part10
This commit is contained in:
@@ -3,9 +3,11 @@ module ElmHub exposing (..)
|
|||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (class, target, href, property, defaultValue)
|
import Html.Attributes exposing (class, target, href, property, defaultValue)
|
||||||
import Html.Events exposing (..)
|
import Html.Events exposing (..)
|
||||||
|
import Html.App as Html
|
||||||
import Auth
|
import Auth
|
||||||
import Json.Decode exposing (Decoder)
|
import Json.Decode exposing (Decoder)
|
||||||
import Json.Decode.Pipeline exposing (..)
|
import Json.Decode.Pipeline exposing (..)
|
||||||
|
import SearchOptions
|
||||||
|
|
||||||
|
|
||||||
getQueryString : String -> String
|
getQueryString : String -> String
|
||||||
@@ -35,6 +37,7 @@ type alias Model =
|
|||||||
{ query : String
|
{ query : String
|
||||||
, results : List SearchResult
|
, results : List SearchResult
|
||||||
, errorMessage : Maybe String
|
, errorMessage : Maybe String
|
||||||
|
, searchOptions : SearchOptions.Model
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -50,9 +53,16 @@ initialModel =
|
|||||||
{ query = "tutorial"
|
{ query = "tutorial"
|
||||||
, results = []
|
, results = []
|
||||||
, errorMessage = Nothing
|
, errorMessage = Nothing
|
||||||
|
, searchOptions = SearchOptions.initialModel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
viewAdvancedSearch : Model -> Html Msg
|
||||||
|
viewAdvancedSearch model =
|
||||||
|
SearchOptions.view model.searchOptions
|
||||||
|
|> Html.map SearchOptionsMsg
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html Msg
|
view : Model -> Html Msg
|
||||||
view model =
|
view model =
|
||||||
div [ class "content" ]
|
div [ class "content" ]
|
||||||
@@ -90,6 +100,7 @@ viewSearchResult result =
|
|||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
= Search
|
= Search
|
||||||
|
| SearchOptionsMsg SearchOptions.Msg
|
||||||
| SetQuery String
|
| SetQuery String
|
||||||
| DeleteById Int
|
| DeleteById Int
|
||||||
| HandleSearchResponse (List SearchResult)
|
| HandleSearchResponse (List SearchResult)
|
||||||
@@ -103,6 +114,19 @@ update searchFeed msg model =
|
|||||||
Search ->
|
Search ->
|
||||||
( model, searchFeed (getQueryString model.query) )
|
( 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 ->
|
SetQuery query ->
|
||||||
( { model | query = query }, Cmd.none )
|
( { 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