module IHP.Pagination.Helpers where
import IHP.Prelude
import IHP.Pagination.Types
getLastPage :: Pagination -> Int
getLastPage :: Pagination -> Int
getLastPage Pagination { Int
pageSize :: Int
pageSize :: Pagination -> Int
pageSize, Int
totalItems :: Int
totalItems :: Pagination -> Int
totalItems } =
if Int
pageSize Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1 then
((Int
totalItems Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
pageSize) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1
else
Int
totalItems Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
pageSize
hasNextPage :: Pagination -> Bool
hasNextPage :: Pagination -> Bool
hasNextPage pagination :: Pagination
pagination@Pagination { Int
currentPage :: Int
currentPage :: Pagination -> Int
currentPage } =
Pagination -> Int
getLastPage Pagination
pagination Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
currentPage
hasPreviousPage :: Pagination -> Bool
hasPreviousPage :: Pagination -> Bool
hasPreviousPage pagination :: Pagination
pagination@Pagination { Int
currentPage :: Pagination -> Int
currentPage :: Int
currentPage } =
Int
currentPage Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1