yesod-page-cursor 1.0.0.0 → 1.0.0.1
raw patch · 4 files changed
+51/−9 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- ChangeLog.md +4/−0
- src/Yesod/Page.hs +23/−7
- test/Spec.hs +22/−0
- yesod-page-cursor.cabal +2/−2
ChangeLog.md view
@@ -4,6 +4,10 @@ None. +## [v1.0.0.1](https://github.com/freckle/yesod-page-cursor/compare/v1.0.0.0...v1.0.0.1)++- Fix missing `previous` link in all but last page+ ## [v1.0.0.0](https://github.com/freckle/yesod-page-cursor/tree/v1.0.0.0) Initial release.
src/Yesod/Page.hs view
@@ -79,24 +79,40 @@ -- We have to fetch page-size+1 items to know if there is a next page or not let (Limit realLimit) = cursorLimit cursor items <- fetchItems cursor { cursorLimit = Limit $ realLimit + 1 }- let page = case cursorPosition cursor of- First -> take realLimit items- Next{} -> take realLimit items- Previous{} -> takeEnd realLimit items- Last -> takeEnd realLimit items + let+ page = case cursorPosition cursor of+ First -> take realLimit items+ Next{} -> take realLimit items+ Previous{} -> takeEnd realLimit items+ Last -> takeEnd realLimit items++ hasExtraItem = length items > realLimit++ hasNextLink = case cursorPosition cursor of+ First -> hasExtraItem+ Next{} -> hasExtraItem+ Previous{} -> True+ Last -> False++ hasPreviousLink = case cursorPosition cursor of+ First -> False+ Next{} -> True+ Previous{} -> hasExtraItem+ Last -> hasExtraItem+ pure Page { pageData = page , pageFirst = cursorRouteAtPosition cursor First , pageNext = do- guard $ length items > realLimit+ guard hasNextLink item <- lastMay page pure $ cursorRouteAtPosition cursor $ Next $ makePosition item , pagePrevious = do- guard $ length items > realLimit+ guard hasPreviousLink item <- headMay page pure $ cursorRouteAtPosition cursor
test/Spec.hs view
@@ -59,6 +59,28 @@ get =<< getLink "next" assertDataKeys [9, 10, 11, 12] + it "traverses a list to next and previous" $ do+ runDB $ insertAssignments 12++ getPaginated SomeR [("teacherId", "1"), ("limit", "4")]++ assertDataKeys [1, 2, 3, 4]+ get =<< getLink "next"+ assertDataKeys [5, 6, 7, 8]+ get =<< getLink "previous"+ assertDataKeys [1, 2, 3, 4]++ it "correctly handles incomplete pages" $ do+ runDB $ insertAssignments 3++ getPaginated SomeR [("teacherId", "1"), ("limit", "2")]++ assertDataKeys [1, 2]+ get =<< getLink "next"+ assertDataKeys [3]+ get =<< getLink "previous"+ assertDataKeys [1, 2]+ it "finds a null next when no items are left" $ do runDB $ insertAssignments 2
yesod-page-cursor.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 234c456d9d19800a8b663bcc97e95b8194624f5d866aba41446788444604a13c+-- hash: b4c5d8ba1fe208184ea08c81eabd470f9b93ba740986c4eb430c742098ddbde4 name: yesod-page-cursor-version: 1.0.0.0+version: 1.0.0.1 description: Cursor based pagination for Yesod homepage: https://github.com/freckle/yesod-page-cursor#readme bug-reports: https://github.com/freckle/yesod-page-cursor/issues