Make changes recommend by @rtfeldman
This commit is contained in:
parent
0ea9f2c904
commit
9be07b4f02
|
@ -1,6 +1,6 @@
|
||||||
import Html exposing (Html, div, h1, input, text)
|
import Html exposing (Html, div, h1, input, text)
|
||||||
import Html.App as App
|
import Html.App as App
|
||||||
import Html.Attributes exposing (placeholder, value)
|
import Html.Attributes exposing (placeholder)
|
||||||
import Html.Events exposing (onInput)
|
import Html.Events exposing (onInput)
|
||||||
import String
|
import String
|
||||||
import Table
|
import Table
|
||||||
|
@ -44,19 +44,19 @@ init people =
|
||||||
|
|
||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
= UpdateQuery String
|
= SetQuery String
|
||||||
| UpdateTableState Table.State
|
| SetTableState Table.State
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
update msg model =
|
update msg model =
|
||||||
case msg of
|
case msg of
|
||||||
UpdateQuery newQuery ->
|
SetQuery newQuery ->
|
||||||
( { model | query = String.toLower newQuery }
|
( { model | query = newQuery }
|
||||||
, Cmd.none
|
, Cmd.none
|
||||||
)
|
)
|
||||||
|
|
||||||
UpdateTableState newState ->
|
SetTableState newState ->
|
||||||
( { model | tableState = newState }
|
( { model | tableState = newState }
|
||||||
, Cmd.none
|
, Cmd.none
|
||||||
)
|
)
|
||||||
|
@ -69,17 +69,15 @@ update msg model =
|
||||||
view : Model -> Html Msg
|
view : Model -> Html Msg
|
||||||
view { people, tableState, query } =
|
view { people, tableState, query } =
|
||||||
let
|
let
|
||||||
|
lowerQuery =
|
||||||
|
String.toLower query
|
||||||
|
|
||||||
acceptablePeople =
|
acceptablePeople =
|
||||||
List.filter (String.contains query << String.toLower << .name) people
|
List.filter (String.contains lowerQuery << String.toLower << .name) people
|
||||||
in
|
in
|
||||||
div []
|
div []
|
||||||
[ h1 [] [ text "Birthplaces of U.S. Presidents" ]
|
[ h1 [] [ text "Birthplaces of U.S. Presidents" ]
|
||||||
, input
|
, input [ placeholder "Search by Name", onInput SetQuery ] []
|
||||||
[ value query
|
|
||||||
, placeholder "Search by Name"
|
|
||||||
, onInput UpdateQuery
|
|
||||||
]
|
|
||||||
[]
|
|
||||||
, Table.view config tableState acceptablePeople
|
, Table.view config tableState acceptablePeople
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -88,7 +86,7 @@ config : Table.Config Person Msg
|
||||||
config =
|
config =
|
||||||
Table.config
|
Table.config
|
||||||
{ toId = .name
|
{ toId = .name
|
||||||
, toMsg = UpdateTableState
|
, toMsg = SetTableState
|
||||||
, columns =
|
, columns =
|
||||||
[ Table.stringColumn "Name" .name
|
[ Table.stringColumn "Name" .name
|
||||||
, Table.intColumn "Year" .year
|
, Table.intColumn "Year" .year
|
||||||
|
|
Loading…
Reference in New Issue