Shift all the parts up a number.

This commit is contained in:
Richard Feldman
2016-04-03 06:37:08 -07:00
parent 49926901e5
commit 39846484fd
40 changed files with 718 additions and 301 deletions

View File

@@ -3,7 +3,6 @@ module ElmHub (..) where
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Html.Lazy exposing (..)
import Http
import Auth
import Task exposing (Task)
@@ -12,7 +11,6 @@ import Json.Decode exposing (Decoder, (:=))
import Json.Encode
import Signal exposing (Address)
import Dict exposing (Dict)
import SearchResult
searchFeed : String -> Task x Action
@@ -33,18 +31,37 @@ searchFeed query =
Task.onError task (\_ -> Task.succeed (SetResults []))
responseDecoder : Decoder (List SearchResult.Model)
responseDecoder : Decoder (List SearchResult)
responseDecoder =
-- TODO make use of SearchResult's decoder
Json.Decode.succeed []
"items" := Json.Decode.list searchResultDecoder
searchResultDecoder : Decoder SearchResult
searchResultDecoder =
Json.Decode.object3
SearchResult
("id" := Json.Decode.int)
("full_name" := Json.Decode.string)
("stargazers_count" := Json.Decode.int)
type alias Model =
{ query : String
, results : Dict SearchResult.ResultId SearchResult.Model
, results : Dict ResultId SearchResult
}
type alias SearchResult =
{ id : ResultId
, name : String
, stars : Int
}
type alias ResultId =
Int
initialModel : Model
initialModel =
{ query = "tutorial"
@@ -69,12 +86,10 @@ view address model =
]
viewSearchResults : Address Action -> Dict SearchResult.ResultId SearchResult.Model -> List Html
viewSearchResults : Address Action -> Dict ResultId SearchResult -> List Html
viewSearchResults address results =
results
|> Dict.values
|> List.sortBy (.stars >> negate)
|> List.map (\_ -> div [] [ text "TODO replace this line with view logic from SearchResult" ])
-- TODO sort by star count and render
[]
onInput address wrap =
@@ -85,11 +100,25 @@ defaultValue str =
property "defaultValue" (Json.Encode.string str)
viewSearchResult : Address Action -> SearchResult -> Html
viewSearchResult address result =
li
[]
[ span [ class "star-count" ] [ text (toString result.stars) ]
, a
[ href ("https://github.com/" ++ result.name), target "_blank" ]
[ text result.name ]
, button
[ class "hide-result", onClick address (DeleteById result.id) ]
[ text "X" ]
]
type Action
= Search
| SetQuery String
| DeleteById SearchResult.ResultId
| SetResults (List SearchResult.Model)
| DeleteById ResultId
| SetResults (List SearchResult)
update : Action -> Model -> ( Model, Effects Action )
@@ -103,17 +132,13 @@ update action model =
SetResults results ->
let
resultsById : Dict SearchResult.ResultId SearchResult.Model
resultsById : Dict ResultId SearchResult
resultsById =
results
|> List.map (\result -> ( result.id, result ))
|> Dict.fromList
-- TODO convert results list into a Dict
Dict.empty
in
( { model | results = resultsById }, Effects.none )
DeleteById id ->
let
newModel =
{ model | results = Dict.remove id model.results }
in
( newModel, Effects.none )
-- TODO delete the result with the given id
( model, Effects.none )

View File

@@ -1,4 +1,4 @@
Part 9
Part 8
======
## Installation

View File

@@ -1,45 +0,0 @@
module SearchResult (..) where
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Json.Decode exposing (Decoder, (:=))
import Signal exposing (Address)
import Dict exposing (Dict)
type alias ResultId =
Int
type alias Model =
{ id : ResultId
, name : String
, stars : Int
}
decoder : Decoder Model
decoder =
Json.Decode.object3
Model
("id" := Json.Decode.int)
("full_name" := Json.Decode.string)
("stargazers_count" := Json.Decode.int)
view : Address a -> Model -> Html
view address result =
li
[]
[ span [ class "star-count" ] [ text (toString result.stars) ]
, a
[ href ("https://github.com/" ++ result.name)
, target "_blank"
]
[ text result.name ]
, button
-- TODO onClick, send a delete action to the address
[ class "hide-result" ]
[ text "X" ]
]