Add TODOs to part11
This commit is contained in:
@@ -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,19 +77,28 @@ init =
|
|||||||
|
|
||||||
view : Model -> Html Msg
|
view : Model -> Html Msg
|
||||||
view model =
|
view model =
|
||||||
div [ class "home-container" ]
|
let
|
||||||
[ input [ class "search-query", onInput SetQuery, defaultValue model.query ] []
|
currentTableState : Table.State
|
||||||
, button [ class "search-button", onClick Search ] [ text "Search" ]
|
currentTableState =
|
||||||
, viewErrorMessage model.errorMessage
|
-- TODO have this use the actual current table state
|
||||||
, Table.view tableConfig model.tableState model.results
|
Table.initialSort "Stars"
|
||||||
]
|
in
|
||||||
|
div [ class "home-container" ]
|
||||||
|
[ input [ class "search-query", onInput SetQuery, defaultValue model.query ] []
|
||||||
|
, button [ class "search-button", onClick Search ] [ text "Search" ]
|
||||||
|
, viewErrorMessage model.errorMessage
|
||||||
|
-- TODO have this use model.results instead of []
|
||||||
|
, Table.view tableConfig currentTableState []
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
tableConfig : Table.Config SearchResult Msg
|
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 )
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user