Add TODOs to part11

This commit is contained in:
Richard Feldman
2016-09-02 23:36:34 -07:00
parent e4e5d107a6
commit cb13ef5ffb

View File

@@ -41,13 +41,24 @@ responseDecoder =
type alias Model = type alias Model =
-- TODO add tableState : Table.State to the Model
{ query : String { query : String
, results : List SearchResult , results : List SearchResult
, errorMessage : Maybe String , errorMessage : Maybe String
, tableState : Table.State
} }
type Msg
= Search
| Visit String
| SetQuery String
| DeleteById Int
| HandleSearchResponse (List SearchResult)
| HandleSearchError (Maybe String)
-- TODO add a new constructor: SetTableState Table.State
| DoNothing
initialQuery : String initialQuery : String
initialQuery = initialQuery =
"tutorial" "tutorial"
@@ -55,10 +66,10 @@ initialQuery =
init : ( Model, Cmd Msg ) init : ( Model, Cmd Msg )
init = init =
-- TODO initialize the Model's tableState to (Table.initialSort "Stars")
( { query = initialQuery ( { query = initialQuery
, results = [] , results = []
, errorMessage = Nothing , errorMessage = Nothing
, tableState = Table.initialSort "Stars"
} }
, githubSearch (getQueryString initialQuery) , githubSearch (getQueryString initialQuery)
) )
@@ -66,11 +77,18 @@ init =
view : Model -> Html Msg view : Model -> Html Msg
view model = view model =
let
currentTableState : Table.State
currentTableState =
-- TODO have this use the actual current table state
Table.initialSort "Stars"
in
div [ class "home-container" ] div [ class "home-container" ]
[ 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
, Table.view tableConfig model.tableState model.results -- TODO have this use model.results instead of []
, Table.view tableConfig currentTableState []
] ]
@@ -78,7 +96,9 @@ tableConfig : Table.Config SearchResult Msg
tableConfig = tableConfig =
Table.config Table.config
{ toId = .id >> toString { toId = .id >> toString
, toMsg = SetTableState , toMsg =
-- TODO have the table use SetTableState for its toMsg
(\tableState -> DoNothing)
, columns = [ starsColumn, nameColumn ] , columns = [ starsColumn, nameColumn ]
} }
@@ -126,17 +146,6 @@ viewSearchResult result =
] ]
type Msg
= Search
| Visit String
| SetQuery String
| DeleteById Int
| HandleSearchResponse (List SearchResult)
| HandleSearchError (Maybe String)
| SetTableState Table.State
| DoNothing
update : Msg -> Model -> ( Model, Cmd Msg ) update : Msg -> Model -> ( Model, Cmd Msg )
update msg model = update msg model =
case msg of case msg of
@@ -166,9 +175,8 @@ update msg model =
in in
( newModel, Cmd.none ) ( newModel, Cmd.none )
SetTableState newState -> -- TODO add a new branch for SetTableState
( { model | tableState = newState }, Cmd.none ) -- which records the new tableState in the Model.
DoNothing -> DoNothing ->
( model, Cmd.none ) ( model, Cmd.none )