From be458d3689c36f137f1bb85c7c622a91491abe95 Mon Sep 17 00:00:00 2001 From: fr33domlover Date: Tue, 7 Jun 2016 11:10:24 +0000 Subject: [PATCH] Pagination: Define page number request param name in one place --- src/Vervis/Paginate.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Vervis/Paginate.hs b/src/Vervis/Paginate.hs index c0d7915..d99a8a0 100644 --- a/src/Vervis/Paginate.hs +++ b/src/Vervis/Paginate.hs @@ -25,6 +25,8 @@ import Control.Arrow (second) import Data.Default.Class (def) import Data.Maybe (fromMaybe) import Data.Monoid ((<>)) +import Data.Text (Text) +import Formatting (sformat, stext, int, (%)) import Yesod.Core (MonadHandler (HandlerSite)) import Yesod.Core.Handler (getCurrentRoute, lookupGetParam) import Yesod.Core.Widget (WidgetT) @@ -39,8 +41,11 @@ import Yesod.Paginate.Local navSettings :: NavSettings navSettings = def +pageParam :: Text +pageParam = "page" + getCurrentPage :: MonadHandler m => m Int -getCurrentPage = lookupGetParam "page" <&> \ mpage -> +getCurrentPage = lookupGetParam pageParam <&> \ mpage -> case mpage of Nothing -> 1 Just page -> @@ -72,5 +77,5 @@ navWidget nm = do route <- fromMaybe (error "Pagination in invalid response content") <$> getCurrentRoute - let url n = (route, "?page=" <> T.pack (show n)) + let url n = (route, sformat ("?" % stext % "=" % int) pageParam n) pageNavWidget nm navWidgetSettings url