aboutsummaryrefslogtreecommitdiff
path: root/client/src/Component/Pages.hs
diff options
context:
space:
mode:
authorJoris2019-10-27 20:26:29 +0100
committerJoris2019-10-27 20:26:29 +0100
commitb97ad942495352c3fc1e0c820cfba82a9693ac7a (patch)
treef554831888929e2eff5e1fe478f92758637d37cf /client/src/Component/Pages.hs
parent8ef4d96644bce59bbb736af6359e644743e5610a (diff)
downloadbudget-b97ad942495352c3fc1e0c820cfba82a9693ac7a.tar.gz
budget-b97ad942495352c3fc1e0c820cfba82a9693ac7a.tar.bz2
budget-b97ad942495352c3fc1e0c820cfba82a9693ac7a.zip
WIP Set up server side paging for incomes
Diffstat (limited to 'client/src/Component/Pages.hs')
-rw-r--r--client/src/Component/Pages.hs37
1 files changed, 21 insertions, 16 deletions
diff --git a/client/src/Component/Pages.hs b/client/src/Component/Pages.hs
index 7284a36..a297222 100644
--- a/client/src/Component/Pages.hs
+++ b/client/src/Component/Pages.hs
@@ -16,38 +16,43 @@ import qualified View.Icon as Icon
data In t = In
{ _in_total :: Dynamic t Int
, _in_perPage :: Int
- , _in_reset :: Event t ()
}
data Out t = Out
- { _out_currentPage :: Dynamic t Int
+ { _out_newPage :: Event t Int
+ , _out_currentPage :: Dynamic t Int
}
view :: forall t m. MonadWidget t m => In t -> m (Out t)
view input = do
- currentPage <- ReflexUtil.divVisibleIf ((> 0) <$> total) $ pageButtons total perPage reset
+ (newPage, currentPage) <- ReflexUtil.divVisibleIf ((> 0) <$> total) $ pageButtons total perPage
return $ Out
- { _out_currentPage = currentPage
+ { _out_newPage = newPage
+ , _out_currentPage = currentPage
}
where
total = _in_total input
perPage = _in_perPage input
- reset = _in_reset input
-pageButtons :: forall t m. MonadWidget t m => Dynamic t Int -> Int -> Event t () -> m (Dynamic t Int)
-pageButtons total perPage reset = do
+pageButtons
+ :: forall t m. MonadWidget t m
+ => Dynamic t Int
+ -> Int
+ -> m (Event t Int, Dynamic t Int)
+pageButtons total perPage = do
R.divClass "pages" $ do
rec
- currentPage <- R.holdDyn 1 . R.leftmost $
- [ firstPageClic
- , previousPageClic
- , pageClic
- , nextPageClic
- , lastPageClic
- , 1 <$ reset
- ]
+ let newPage = R.leftmost
+ [ firstPageClic
+ , previousPageClic
+ , pageClic
+ , nextPageClic
+ , lastPageClic
+ ]
+
+ currentPage <- R.holdDyn 1 newPage
firstPageClic <- pageButton noCurrentPage (R.constDyn 1) Icon.doubleLeftBar
@@ -60,7 +65,7 @@ pageButtons total perPage reset = do
lastPageClic <- pageButton noCurrentPage maxPage Icon.doubleRightBar
- return currentPage
+ return (newPage, currentPage)
where maxPage = R.ffor total (\t -> ceiling $ toRational t / toRational perPage)
pageEvent = R.switch . R.current . fmap R.leftmost