view : Signal.Address Action -> Model -> Html (1)
view address model =
div
[ class "filter-list" ] (2)
[ searchInputView address model
, ul
[]
(List.map (\m -> itemView address m model) model.filteredModules) (3)
]
searchInputView : Signal.Address Action -> Model -> Html (4)
searchInputView address model =
let
options =
{ preventDefault = True, stopPropagation = False }
keyActions =
Dict.fromList [ ( 38, Prev ), ( 40, Next ), ( 13, Select ), ( 27, Close ) ] (5)
dec =
(Json.customDecoder (6)
keyCode
(\k ->
if Dict.member k keyActions then
Ok k
else
Err "not handling that key"
)
)
handleKeydown k = (7)
Maybe.withDefault NoOp (Dict.get k keyActions) |> Signal.message address
in
input (8)
[ value model.searchStr
, class "search"
, type' "text"
, placeholder "search"
, on "input" targetValue (\str -> Signal.message address (Filter str))
, onWithOptions "keydown" options dec handleKeydown
]
[]
itemView : Signal.Address Action -> Modul -> Model -> Html
itemView address mod model = (9)
let
pipeM = (10)
flip Maybe.andThen
itemClass = (11)
model.selected
|> pipeM
(\sel ->
if (sel == mod) then
Just "selected"
else
Nothing
)
|> Maybe.withDefault ""
in
li
[ class itemClass
, onClick address (ClickSelect mod.file)
]
[ p [] [ text mod.name ]
, p [ class "binding" ] [ text (mod.packageName ++ " - " ++ mod.version) ]
]