Pagination: Define page number request param name in one place

This commit is contained in:
fr33domlover 2016-06-07 11:10:24 +00:00
parent 5e04f951f2
commit be458d3689

View file

@ -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