Add TODOs to 8
This commit is contained in:
@@ -9,6 +9,7 @@ import Effects exposing (Effects)
|
|||||||
import Json.Decode exposing (Decoder, (:=))
|
import Json.Decode exposing (Decoder, (:=))
|
||||||
import Json.Encode
|
import Json.Encode
|
||||||
import Signal exposing (Address)
|
import Signal exposing (Address)
|
||||||
|
import Dict exposing (Dict)
|
||||||
|
|
||||||
|
|
||||||
searchFeed : String -> Task x Action
|
searchFeed : String -> Task x Action
|
||||||
@@ -18,7 +19,7 @@ searchFeed query =
|
|||||||
url =
|
url =
|
||||||
"https://api.github.com/search/repositories?q="
|
"https://api.github.com/search/repositories?q="
|
||||||
++ query
|
++ query
|
||||||
++ "+language:elm&sort=stars&order=desc"
|
++ "+language:elm"
|
||||||
|
|
||||||
task =
|
task =
|
||||||
Http.get responseDecoder url
|
Http.get responseDecoder url
|
||||||
@@ -43,7 +44,7 @@ searchResultDecoder =
|
|||||||
|
|
||||||
type alias Model =
|
type alias Model =
|
||||||
{ query : String
|
{ query : String
|
||||||
, results : List SearchResult
|
, results : Dict ResultId SearchResult
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ type alias ResultId =
|
|||||||
initialModel : Model
|
initialModel : Model
|
||||||
initialModel =
|
initialModel =
|
||||||
{ query = "tutorial"
|
{ query = "tutorial"
|
||||||
, results = []
|
, results = Dict.empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -78,10 +79,16 @@ view address model =
|
|||||||
, button [ class "search-button", onClick address Search ] [ text "Search" ]
|
, button [ class "search-button", onClick address Search ] [ text "Search" ]
|
||||||
, ul
|
, ul
|
||||||
[ class "results" ]
|
[ class "results" ]
|
||||||
(List.map (viewSearchResult address) model.results)
|
(viewSearchResults address model.results)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
viewSearchResults : Address Action -> Dict ResultId SearchResult -> List Html
|
||||||
|
viewSearchResults address results =
|
||||||
|
-- TODO sort by star count and render
|
||||||
|
[]
|
||||||
|
|
||||||
|
|
||||||
onInput address wrap =
|
onInput address wrap =
|
||||||
on "input" targetValue (\val -> Signal.message address (wrap val))
|
on "input" targetValue (\val -> Signal.message address (wrap val))
|
||||||
|
|
||||||
@@ -122,18 +129,13 @@ update action model =
|
|||||||
|
|
||||||
SetResults results ->
|
SetResults results ->
|
||||||
let
|
let
|
||||||
newModel =
|
-- TODO convert results list into a Dict
|
||||||
{ model | results = results }
|
resultsById : Dict ResultId SearchResult
|
||||||
|
resultsById =
|
||||||
|
Dict.empty
|
||||||
in
|
in
|
||||||
( newModel, Effects.none )
|
( { model | results = resultsById }, Effects.none )
|
||||||
|
|
||||||
DeleteById idToHide ->
|
DeleteById id ->
|
||||||
let
|
-- TODO delete the result with the given id
|
||||||
newResults =
|
( model, Effects.none )
|
||||||
model.results
|
|
||||||
|> List.filter (\{ id } -> id /= idToHide)
|
|
||||||
|
|
||||||
newModel =
|
|
||||||
{ model | results = newResults }
|
|
||||||
in
|
|
||||||
( newModel, Effects.none )
|
|
||||||
|
|||||||
Reference in New Issue
Block a user