From bb316286b0859b5648c61f44c88399f4c1aad9cd Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 2 Jan 2016 19:07:19 +0100 Subject: Use start-app for elm --- src/client/elm/View/LoggedIn/Paging.elm | 47 +++++++++++++++++---------------- 1 file changed, 24 insertions(+), 23 deletions(-) (limited to 'src/client/elm/View/LoggedIn/Paging.elm') diff --git a/src/client/elm/View/LoggedIn/Paging.elm b/src/client/elm/View/LoggedIn/Paging.elm index e40c5aa..154686a 100644 --- a/src/client/elm/View/LoggedIn/Paging.elm +++ b/src/client/elm/View/LoggedIn/Paging.elm @@ -2,23 +2,24 @@ module View.LoggedIn.Paging ( paymentsPaging ) where +import Signal exposing (Address) + import Html exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (..) +import Model.Action exposing (..) +import Model.Action.LoggedInAction exposing (..) import Model.View.LoggedInView exposing (..) import Model.Payment exposing (perPage) -import Update exposing (..) -import Update.LoggedIn exposing (..) - import View.Icon exposing (renderIcon) showedPages : Int showedPages = 5 -paymentsPaging : LoggedInView -> Html -paymentsPaging loggedInView = +paymentsPaging : Address Action -> LoggedInView -> Html +paymentsPaging address loggedInView = let maxPage = ceiling (toFloat loggedInView.paymentsCount / toFloat perPage) pages = truncatePages loggedInView.currentPage [1..maxPage] in if maxPage == 1 @@ -28,12 +29,12 @@ paymentsPaging loggedInView = div [ class "pages" ] ( ( if loggedInView.currentPage > 1 - then [ firstPage, previousPage loggedInView ] + then [ firstPage address, previousPage address loggedInView ] else [] ) - ++ ( List.map (paymentsPage loggedInView) pages) + ++ ( List.map (paymentsPage address loggedInView) pages) ++ ( if loggedInView.currentPage < maxPage - then [ nextPage loggedInView, lastPage maxPage ] + then [ nextPage address loggedInView, lastPage address maxPage ] else [] ) ) @@ -52,47 +53,47 @@ truncatePages currentPage pages = [(currentPage - showedLeftPages)..(currentPage + showedRightPages)] in List.filter (flip List.member pages) truncatedPages -firstPage : Html -firstPage = +firstPage : Address Action -> Html +firstPage address = button [ class "page" - , onClick actions.address (UpdateLoggedIn (UpdatePage 1)) + , onClick address (UpdateLoggedIn (UpdatePage 1)) ] [ renderIcon "fast-backward" ] -previousPage : LoggedInView -> Html -previousPage loggedInView = +previousPage : Address Action -> LoggedInView -> Html +previousPage address loggedInView = button [ class "page" - , onClick actions.address (UpdateLoggedIn (UpdatePage (loggedInView.currentPage - 1))) + , onClick address (UpdateLoggedIn (UpdatePage (loggedInView.currentPage - 1))) ] [ renderIcon "backward" ] -nextPage : LoggedInView -> Html -nextPage loggedInView = +nextPage : Address Action -> LoggedInView -> Html +nextPage address loggedInView = button [ class "page" - , onClick actions.address (UpdateLoggedIn (UpdatePage (loggedInView.currentPage + 1))) + , onClick address (UpdateLoggedIn (UpdatePage (loggedInView.currentPage + 1))) ] [ renderIcon "forward" ] -lastPage : Int -> Html -lastPage maxPage = +lastPage : Address Action -> Int -> Html +lastPage address maxPage = button [ class "page" - , onClick actions.address (UpdateLoggedIn (UpdatePage maxPage)) + , onClick address (UpdateLoggedIn (UpdatePage maxPage)) ] [ renderIcon "fast-forward" ] -paymentsPage : LoggedInView -> Int -> Html -paymentsPage loggedInView page = +paymentsPage : Address Action -> LoggedInView -> Int -> Html +paymentsPage address loggedInView page = let onCurrentPage = page == loggedInView.currentPage in button [ classList [ ("page", True) , ("current", onCurrentPage) ] - , onClick actions.address <| + , onClick address <| if onCurrentPage then NoOp else UpdateLoggedIn (UpdatePage page) ] [ text (toString page) ] -- cgit v1.2.3