@@ -5,16 +5,19 @@ import Html exposing (..)
55import Html.Attributes as Attr
66import Html.Events as Ev
77import Page exposing (..)
8+import Search
89import Utils exposing (..)
910
1011
1112type alias Model =
1213 { ciphers : Bridge.Sub_LoadCiphers_List
14+ , search : String
1315 }
1416
1517
1618type Msg
1719 = Noop
20+ | UpdateSearch String
1821
1922
2023type alias Callbacks msg =
@@ -25,7 +28,7 @@ type alias Callbacks msg =
2528page : Callbacks emsg -> Page Bridge.Sub_LoadCiphers_List Model Msg emsg
2629page callbacks liftMsg =
2730 { init = \ciphers -> Tuple.mapSecond (Cmd.map liftMsg) (init ciphers)
28− , view = view callbacks
31+ , view = view callbacks liftMsg
2932 , update = \msg model -> update callbacks liftMsg msg model
3033 , subscriptions = \model -> subscriptions model |> Sub.map liftMsg
3134 , title = always "Passwords"
@@ -34,7 +37,7 @@ page callbacks liftMsg =
3437
3538init : Bridge.Sub_LoadCiphers_List -> ( Model, Cmd Msg )
3639init ciphers =
37− ( { ciphers = ciphers }
40+ ( { ciphers = ciphers, search = "" }
3841 , Cmd.none
3942 )
4043
@@ -45,24 +48,43 @@ update {} liftMsg msg model =
4548 Noop ->
4649 ( Ok model, Cmd.none )
4750
51+ UpdateSearch s ->
52+ ( Ok { model | search = s }, Cmd.none )
53+
4854
4955subscriptions : Model -> Sub Msg
5056subscriptions model =
5157 Sub.none
5258
5359
54−view : Callbacks emsg -> Model -> List (Html emsg)
55−view { selected } { ciphers } =
56− [ ul [ Attr.class "p-list--divided" ]
57− (List.map
58− (\{ name, date, id } ->
59− li [ Attr.class "p-list__item cipher-row", Ev.onClick (selected id) ]
60− [ div [ Attr.class "cipher-row-container" ]
61− [ p [] [ text name ]
62− , p [ Attr.class "p-text--small u-align-text--right u-text--muted" ] [ text date ]
60+view : Callbacks emsg -> (Msg -> emsg) -> Model -> List (Html emsg)
61+view { selected } liftMsg { ciphers, search } =
62+ [ input
63+ [ Attr.type_ "search"
64+ , Attr.value search
65+ , Ev.onInput (liftMsg << UpdateSearch)
66+ , Attr.placeholder "Search"
67+ , Attr.attribute "autocomplete" "off"
68+ ]
69+ []
70+ , ul [ Attr.class "p-list--divided" ]
71+ (ciphers
72+ |> Search.searchList (cipherSearch search)
73+ |> List.map
74+ (\{ name, date, id } ->
75+ li [ Attr.class "p-list__item cipher-row", Ev.onClick (selected id) ]
76+ [ div [ Attr.class "cipher-row-container" ]
77+ [ p [] [ text name ]
78+ , p [ Attr.class "p-text--small u-align-text--right u-text--muted" ] [ text date ]
79+ ]
6380 ]
64− ]
65− )
66− ciphers
81+ )
6782 )
6883 ]
84+
85+
86+cipherSearch : String -> Search.Search Bridge.Sub_LoadCiphers
87+cipherSearch query =
88+ Search.Search
89+ [ ( query, \q { name } -> Search.search q name )
90+ ]