@@ -6,6 +6,7 @@ import Html.Attributes as Attr
6import Html.Events as Ev
6import Html.Events as Ev
7import Html.Keyed as Keyed
7import Html.Keyed as Keyed
8import Html.Lazy as Lazy
8import Html.Lazy as Lazy
9import Page exposing (..)
10import Page exposing (..)
10import Pages.Navigation as Navigation
11import Pages.Navigation as Navigation
11import Search
12import Search
@@ -17,6 +18,8 @@ type alias Model =
17 , search : String
18 , search : String
18 , menuVisible : Bool
19 , menuVisible : Bool
19 , ciphersListFilter : CiphersFilter
20 , ciphersListFilter : CiphersFilter
21+ , scroll : InfiniteScroll.Model Msg
22+ , sublist : { end : Int }
@@ -77,6 +80,8 @@ type Msg
77 | ToggleMenu
80 | ToggleMenu
78 | UpdateFilter CiphersFilter
81 | UpdateFilter CiphersFilter
83+ | LoadMore InfiniteScroll.Direction
84+ | InfiniteScrollMsg InfiniteScroll.Msg
82type alias Callbacks msg =
87type alias Callbacks msg =
@@ -119,6 +124,8 @@ init ciphers =
119 , search = ""
124 , search = ""
120 , menuVisible = False
125 , menuVisible = False
121 , ciphersListFilter = AllCiphers
126 , ciphersListFilter = AllCiphers
127+ , scroll = InfiniteScroll.init (LoadMore >> pureCmd)
128+ , sublist = { end = 20 }
123 , Cmd.none
130 , Cmd.none
@@ -142,6 +149,25 @@ update { logOut } liftMsg msg model =
142 LogOut ->
149 LogOut ->
143 ( Ok model, pureCmd logOut )
150 ( Ok model, pureCmd logOut )
152+ LoadMore direction ->
156+ InfiniteScroll.Top ->
157+ { end = model.sublist.end }
159+ InfiniteScroll.Bottom ->
160+ { end = min (model.sublist.end + 10) (List.length model.ciphers) }
162+ ( Ok { model | sublist = newSublist, scroll = InfiniteScroll.stopLoading model.scroll }, Cmd.none )
164+ InfiniteScrollMsg msg_ ->
167+ InfiniteScroll.update InfiniteScrollMsg msg_ model.scroll
169+ ( Ok { model | scroll = scroll }, Cmd.map liftMsg cmd )
146subscriptions : Model -> Sub Msg
172subscriptions : Model -> Sub Msg
147subscriptions _ =
173subscriptions _ =
@@ -149,7 +175,7 @@ subscriptions _ =
151view : Callbacks emsg -> (Msg -> emsg) -> Model -> List (Html emsg)
177view : Callbacks emsg -> (Msg -> emsg) -> Model -> List (Html emsg)
152−view { selected } liftMsg { ciphers, search, ciphersListFilter } =
178+view { selected } liftMsg { ciphers, search, ciphersListFilter, sublist } =
154 [ Attr.type_ "search"
180 [ Attr.type_ "search"
155 , Attr.value search
181 , Attr.value search
@@ -160,13 +186,13 @@ view { selected } liftMsg { ciphers, search, ciphersListFilter } =
161 , ciphers
187 , ciphers
162 |> applyCipherFilter ciphersListFilter
188 |> applyCipherFilter ciphersListFilter
163− |> Search.searchList search .name (Lazy.lazy2 showCiphers selected)
189+ |> Search.searchList search .name (List.take sublist.end >> Lazy.lazy3 showCiphers liftMsg selected)
167−showCiphers : (String -> msg) -> Bridge.Sub_LoadCiphers_List -> Html msg
193+showCiphers : (Msg -> msg) -> (String -> msg) -> Bridge.Sub_LoadCiphers_List -> Html msg
168−showCiphers selected ciphers =
194+showCiphers liftMsg selected ciphers =
169− Keyed.ul [ Attr.class "p-list--divided" ]
195+ Keyed.ul [ Attr.class "p-list--divided", InfiniteScroll.infiniteScroll (InfiniteScrollMsg >> liftMsg), Attr.class "ciphers-list no-scroll-bar" ]
171 |> List.map
197 |> List.map
172 (\{ name, date, id } ->
198 (\{ name, date, id } ->