diff --git a/src/Data/Paginate/Local.hs b/src/Data/Paginate/Local.hs index 517d8a6..5b79c20 100644 --- a/src/Data/Paginate/Local.hs +++ b/src/Data/Paginate/Local.hs @@ -109,10 +109,10 @@ data NavModel = NavModel { nmFirst :: Bool , nmPrevJumps :: [Int] - , nmPrev :: [Int] + , nmPrev :: Maybe ([Int], Int) , nmCurrent :: Int , nmTotal :: Int - , nmNext :: [Int] + , nmNext :: Maybe (Int, [Int]) , nmNextJumps :: [Int] , nmLast :: Bool } @@ -131,14 +131,14 @@ navModel ns curr total = NavModel , nmPrevJumps = [] --TODO , nmPrev = if curr == 1 || navNext ns < 1 - then [] - else [max 1 (curr - navNext ns) .. curr - 1] + then Nothing + else Just ([max 1 (curr - navNext ns) .. curr - 2], curr - 1) , nmCurrent = curr , nmTotal = total , nmNext = if curr >= total || navNext ns < 1 - then [] - else [curr + 1 .. min total (curr + navNext ns)] + then Nothing + else Just (curr + 1, [curr + 2 .. min total (curr + navNext ns)]) , nmNextJumps = [] --TODO , nmLast = navEdges ns } diff --git a/src/Yesod/Paginate/Local.hs b/src/Yesod/Paginate/Local.hs index f219d50..1ddb90b 100644 --- a/src/Yesod/Paginate/Local.hs +++ b/src/Yesod/Paginate/Local.hs @@ -34,11 +34,12 @@ import Text.Blaze (ToMarkup) import Yesod.Core (RenderRoute (..)) import Yesod.Core.Widget (WidgetT, whamlet) +import qualified Data.Text as T (pack) import qualified Formatting as F import Data.Paginate.Local --- | Settings for building a UI page navigation widget. +-- | Settings for building a page navigation UI widget. data NavWidgetSettings = NavWidgetSettings { -- | Label for the first page link. Examples: 1, First, ≪, ⋘. nwsFirst :: Text @@ -82,7 +83,27 @@ pageNavWidget nm nws mklink = $if nmFirst nm
  • ^{link 1 $ nwsFirst nws} + + $#--------- TODO prev jumps -------- + + $maybe (ps, p) <- nmPrev nm + $forall m <- ps +
  • + ^{link m (T.pack $ show m)} +
  • + ^{link p (nwsPrev nws p)} +
  • #{nwsCurrent nws (nmCurrent nm) (nmTotal nm)} + + $maybe (n, ns) <- nmNext nm +
  • + ^{link n (nwsNext nws n)} + $forall m <- ns +
  • + ^{link m (T.pack $ show m)} + + $#--------- TODO next jumps -------- + $if nmLast nm
  • ^{link (nmTotal nm) (nwsLast nws $ nmTotal nm)}