Add a bit on lazy
This commit is contained in:
@@ -3,6 +3,7 @@ module Component.ElmHub (..) where
|
|||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
import Html.Events exposing (..)
|
import Html.Events exposing (..)
|
||||||
|
import Html.Lazy exposing (..)
|
||||||
import Http
|
import Http
|
||||||
import Task exposing (Task)
|
import Task exposing (Task)
|
||||||
import Effects exposing (Effects)
|
import Effects exposing (Effects)
|
||||||
@@ -69,10 +70,30 @@ 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 -> List Component.SearchResult.Model -> List Html
|
||||||
|
viewSearchResults address results =
|
||||||
|
results
|
||||||
|
|> filterResults
|
||||||
|
|> List.map (lazy2 viewSearchResult address)
|
||||||
|
|
||||||
|
|
||||||
|
filterResults : List Component.SearchResult.Model -> List Component.SearchResult.Model
|
||||||
|
filterResults results =
|
||||||
|
case results of
|
||||||
|
[] ->
|
||||||
|
[]
|
||||||
|
|
||||||
|
first :: rest ->
|
||||||
|
if first.stars > 0 then
|
||||||
|
first :: (filterResults rest)
|
||||||
|
else
|
||||||
|
filterResults rest
|
||||||
|
|
||||||
|
|
||||||
onInput address wrap =
|
onInput address wrap =
|
||||||
on "input" targetValue (\val -> Signal.message address (wrap val))
|
on "input" targetValue (\val -> Signal.message address (wrap val))
|
||||||
|
|
||||||
@@ -85,7 +106,7 @@ viewSearchResult : Address Action -> Component.SearchResult.Model -> Html
|
|||||||
viewSearchResult address result =
|
viewSearchResult address result =
|
||||||
Component.SearchResult.view
|
Component.SearchResult.view
|
||||||
(Signal.forwardTo address (UpdateSearchResult result.id))
|
(Signal.forwardTo address (UpdateSearchResult result.id))
|
||||||
result
|
(Debug.log "rendering result..." result)
|
||||||
|
|
||||||
|
|
||||||
type Action
|
type Action
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ module ElmHub (..) where
|
|||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
import Html.Events exposing (..)
|
import Html.Events exposing (..)
|
||||||
|
import Html.Lazy exposing (..)
|
||||||
import Http
|
import Http
|
||||||
import Task exposing (Task)
|
import Task exposing (Task)
|
||||||
import Effects exposing (Effects)
|
import Effects exposing (Effects)
|
||||||
@@ -88,9 +89,17 @@ viewSearchResults address results =
|
|||||||
results
|
results
|
||||||
|> Dict.values
|
|> Dict.values
|
||||||
|> List.sortBy (.stars >> negate)
|
|> List.sortBy (.stars >> negate)
|
||||||
|
|> filterResults
|
||||||
|> List.map (viewSearchResult address)
|
|> List.map (viewSearchResult address)
|
||||||
|
|
||||||
|
|
||||||
|
filterResults : List SearchResult -> List SearchResult
|
||||||
|
filterResults results =
|
||||||
|
-- TODO filter out repos with 0 stars
|
||||||
|
-- using a case-expression rather than List.filter
|
||||||
|
[]
|
||||||
|
|
||||||
|
|
||||||
onInput address wrap =
|
onInput address wrap =
|
||||||
on "input" targetValue (\val -> Signal.message address (wrap val))
|
on "input" targetValue (\val -> Signal.message address (wrap val))
|
||||||
|
|
||||||
@@ -105,7 +114,15 @@ viewSearchResult address result =
|
|||||||
[]
|
[]
|
||||||
[ span [ class "star-count" ] [ text (toString result.stars) ]
|
[ span [ class "star-count" ] [ text (toString result.stars) ]
|
||||||
, a
|
, a
|
||||||
[ href ("https://github.com/" ++ result.name), target "_blank" ]
|
[ href
|
||||||
|
("https://github.com/"
|
||||||
|
++ (Debug.log "Viewing" result.name)
|
||||||
|
{- TODO we should no longer see this
|
||||||
|
console output when typing in the search box!
|
||||||
|
-}
|
||||||
|
)
|
||||||
|
, target "_blank"
|
||||||
|
]
|
||||||
[ text result.name ]
|
[ text result.name ]
|
||||||
, button
|
, button
|
||||||
[ class "hide-result", onClick address (DeleteById result.id) ]
|
[ class "hide-result", onClick address (DeleteById result.id) ]
|
||||||
|
|||||||
Reference in New Issue
Block a user