From d500b85c572de9a31534da85eadd939ae904bfdd Mon Sep 17 00:00:00 2001
From: fr33domlover <fr33domlover@rel4tion.org>
Date: Tue, 7 Jun 2016 12:57:05 +0000
Subject: [PATCH] Pagination widget: Display prev and next pages' links

---
 src/Data/Paginate/Local.hs  | 12 ++++++------
 src/Yesod/Paginate/Local.hs | 23 ++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 7 deletions(-)

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
                 <li>
                   ^{link 1 $ nwsFirst nws}
+
+              $#--------- TODO prev jumps --------
+
+              $maybe (ps, p) <- nmPrev nm
+                $forall m <- ps
+                  <li>
+                    ^{link m (T.pack $ show m)}
+                <li>
+                  ^{link p (nwsPrev nws p)}
+
               <li>#{nwsCurrent nws (nmCurrent nm) (nmTotal nm)}
+
+              $maybe (n, ns) <- nmNext nm
+                <li>
+                  ^{link n (nwsNext nws n)}
+                $forall m <- ns
+                  <li>
+                    ^{link m (T.pack $ show m)}
+
+              $#--------- TODO next jumps --------
+
               $if nmLast nm
                 <li>
                   ^{link (nmTotal nm) (nwsLast nws $ nmTotal nm)}