Pagination: Define page number request param name in one place
This commit is contained in:
parent
5e04f951f2
commit
be458d3689
1 changed files with 7 additions and 2 deletions
|
@ -25,6 +25,8 @@ import Control.Arrow (second)
|
||||||
import Data.Default.Class (def)
|
import Data.Default.Class (def)
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
import Data.Monoid ((<>))
|
import Data.Monoid ((<>))
|
||||||
|
import Data.Text (Text)
|
||||||
|
import Formatting (sformat, stext, int, (%))
|
||||||
import Yesod.Core (MonadHandler (HandlerSite))
|
import Yesod.Core (MonadHandler (HandlerSite))
|
||||||
import Yesod.Core.Handler (getCurrentRoute, lookupGetParam)
|
import Yesod.Core.Handler (getCurrentRoute, lookupGetParam)
|
||||||
import Yesod.Core.Widget (WidgetT)
|
import Yesod.Core.Widget (WidgetT)
|
||||||
|
@ -39,8 +41,11 @@ import Yesod.Paginate.Local
|
||||||
navSettings :: NavSettings
|
navSettings :: NavSettings
|
||||||
navSettings = def
|
navSettings = def
|
||||||
|
|
||||||
|
pageParam :: Text
|
||||||
|
pageParam = "page"
|
||||||
|
|
||||||
getCurrentPage :: MonadHandler m => m Int
|
getCurrentPage :: MonadHandler m => m Int
|
||||||
getCurrentPage = lookupGetParam "page" <&> \ mpage ->
|
getCurrentPage = lookupGetParam pageParam <&> \ mpage ->
|
||||||
case mpage of
|
case mpage of
|
||||||
Nothing -> 1
|
Nothing -> 1
|
||||||
Just page ->
|
Just page ->
|
||||||
|
@ -72,5 +77,5 @@ navWidget nm = do
|
||||||
route <-
|
route <-
|
||||||
fromMaybe (error "Pagination in invalid response content") <$>
|
fromMaybe (error "Pagination in invalid response content") <$>
|
||||||
getCurrentRoute
|
getCurrentRoute
|
||||||
let url n = (route, "?page=" <> T.pack (show n))
|
let url n = (route, sformat ("?" % stext % "=" % int) pageParam n)
|
||||||
pageNavWidget nm navWidgetSettings url
|
pageNavWidget nm navWidgetSettings url
|
||||||
|
|
Loading…
Reference in a new issue