@@ -5,16 +5,19 @@ import Html exposing (..)
5import Html.Attributes as Attr
5import Html.Attributes as Attr
6import Html.Events as Ev
6import Html.Events as Ev
7import Page exposing (..)
7import Page exposing (..)
8import Utils exposing (..)
9import Utils exposing (..)
11type alias Model =
12type alias Model =
12 { ciphers : Bridge.Sub_LoadCiphers_List
13 { ciphers : Bridge.Sub_LoadCiphers_List
20+ | UpdateSearch String
20type alias Callbacks msg =
23type alias Callbacks msg =
@@ -25,7 +28,7 @@ type alias Callbacks msg =
25page : Callbacks emsg -> Page Bridge.Sub_LoadCiphers_List Model Msg emsg
28page : Callbacks emsg -> Page Bridge.Sub_LoadCiphers_List Model Msg emsg
26page callbacks liftMsg =
29page callbacks liftMsg =
27 { init = \ciphers -> Tuple.mapSecond (Cmd.map liftMsg) (init ciphers)
30 { init = \ciphers -> Tuple.mapSecond (Cmd.map liftMsg) (init ciphers)
28− , view = view callbacks
31+ , view = view callbacks liftMsg
29 , update = \msg model -> update callbacks liftMsg msg model
32 , update = \msg model -> update callbacks liftMsg msg model
30 , subscriptions = \model -> subscriptions model |> Sub.map liftMsg
33 , subscriptions = \model -> subscriptions model |> Sub.map liftMsg
31 , title = always "Passwords"
34 , title = always "Passwords"
@@ -34,7 +37,7 @@ page callbacks liftMsg =
35init : Bridge.Sub_LoadCiphers_List -> ( Model, Cmd Msg )
38init : Bridge.Sub_LoadCiphers_List -> ( Model, Cmd Msg )
36init ciphers =
39init ciphers =
37− ( { ciphers = ciphers }
40+ ( { ciphers = ciphers, search = "" }
38 , Cmd.none
41 , Cmd.none
@@ -45,24 +48,43 @@ update {} liftMsg msg model =
46 ( Ok model, Cmd.none )
49 ( Ok model, Cmd.none )
52+ ( Ok { model | search = s }, Cmd.none )
49subscriptions : Model -> Sub Msg
55subscriptions : Model -> Sub Msg
50subscriptions model =
56subscriptions model =
54−view : Callbacks emsg -> Model -> List (Html emsg)
60+view : Callbacks emsg -> (Msg -> emsg) -> Model -> List (Html emsg)
55−view { selected } { ciphers } =
61+view { selected } liftMsg { ciphers, search } =
63+ [ Attr.type_ "search"
65+ , Ev.onInput (liftMsg << UpdateSearch)
66+ , Attr.placeholder "Search"
67+ , Attr.attribute "autocomplete" "off"
56− [ ul [ Attr.class "p-list--divided" ]
70+ , ul [ Attr.class "p-list--divided" ]
72+ |> Search.searchList (cipherSearch search)
57− (List.map
73+ |> List.map
58− (\{ name, date, id } ->
74+ (\{ name, date, id } ->
59− li [ Attr.class "p-list__item cipher-row", Ev.onClick (selected id) ]
75+ li [ Attr.class "p-list__item cipher-row", Ev.onClick (selected id) ]
60− [ div [ Attr.class "cipher-row-container" ]
76+ [ div [ Attr.class "cipher-row-container" ]
61− [ p [] [ text name ]
77+ [ p [] [ text name ]
62− , p [ Attr.class "p-text--small u-align-text--right u-text--muted" ] [ text date ]
78+ , p [ Attr.class "p-text--small u-align-text--right u-text--muted" ] [ text date ]
86+cipherSearch : String -> Search.Search Bridge.Sub_LoadCiphers
89+ [ ( query, \q { name } -> Search.search q name )