Solution for advanced/part5

This commit is contained in:
Richard Feldman
2018-08-14 03:17:02 -04:00
parent 176b28ae6b
commit 46870e98bf
3 changed files with 33 additions and 83 deletions

View File

@@ -109,7 +109,7 @@ view model =
]
, Feed.viewArticles model.timeZone feed
|> List.map (Html.map GotFeedMsg)
, [ viewPagination (Feed.articles feed) ]
, [ PaginatedList.view ClickedFeedPage (Feed.articles feed) ]
]
]
@@ -155,46 +155,6 @@ viewBanner =
-- PAGINATION
{-| 👉 TODO: Relocate `viewPagination` into `PaginatedList.view` and make it reusable,
then refactor both Page.Home and Page.Profile to use it!
💡 HINT: Make `PaginatedList.view` return `Html msg` instead of `Html Msg`.
(You'll need to introduce at least one extra argument for this to work.)
-}
viewPagination : PaginatedList (Article Preview) -> Html Msg
viewPagination list =
let
viewPageLink currentPage =
pageLink currentPage (currentPage == page list)
in
if total list > 1 then
List.range 1 (total list)
|> List.map viewPageLink
|> ul [ class "pagination" ]
else
Html.text ""
pageLink : Int -> Bool -> Html Msg
pageLink targetPage isActive =
li [ classList [ ( "page-item", True ), ( "active", isActive ) ] ]
[ a
[ class "page-link"
, onClick (ClickedFeedPage targetPage)
-- The RealWorld CSS requires an href to work properly.
, href ""
]
[ text (String.fromInt targetPage) ]
]
-- TABS