aboutsummaryrefslogtreecommitdiff
path: root/client/src/Component
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/Component')
-rw-r--r--client/src/Component/Pages.hs37
-rw-r--r--client/src/Component/Table.hs20
2 files changed, 22 insertions, 35 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
diff --git a/client/src/Component/Table.hs b/client/src/Component/Table.hs
index a02eaa7..7103abd 100644
--- a/client/src/Component/Table.hs
+++ b/client/src/Component/Table.hs
@@ -10,7 +10,6 @@ import qualified Reflex.Dom as R
import qualified Component.Button as Button
import qualified Component.Modal as Modal
-import qualified Component.Pages as Pages
import qualified Util.Reflex as ReflexUtil
import qualified View.Icon as Icon
@@ -18,8 +17,6 @@ data In m t h r a = In
{ _in_headerLabel :: h -> Text
, _in_rows :: Dynamic t [r]
, _in_cell :: h -> r -> Text
- , _in_perPage :: Int
- , _in_resetPage :: Event t ()
, _in_cloneModal :: r -> Modal.Content t m a
, _in_editModal :: r -> Modal.Content t m a
, _in_deleteModal :: r -> Modal.Content t m a
@@ -47,12 +44,7 @@ view input =
R.divClass "cell" $ R.blank
R.divClass "cell" $ R.blank
- let rows = getRange
- (_in_perPage input)
- <$> (Pages._out_currentPage pages)
- <*> (_in_rows input)
-
- R.simpleList rows $ \r ->
+ R.simpleList (_in_rows input) $ \r ->
R.divClass "row" $ do
flip mapM_ [minBound..] $ \h ->
R.divClass "cell" $
@@ -104,12 +96,6 @@ view input =
return (cloned, edited, deleted)
- pages <- Pages.view $ Pages.In
- { Pages._in_total = length <$> _in_rows input
- , Pages._in_perPage = _in_perPage input
- , Pages._in_reset = _in_resetPage input
- }
-
let add = R.switch . R.current . fmap (R.leftmost . map (\(a, _, _) -> a)) $ result
edit = R.switch . R.current . fmap (R.leftmost . map (\(_, a, _) -> a)) $ result
delete = R.switch . R.current . fmap (R.leftmost . map (\(_, _, a) -> a)) $ result
@@ -119,7 +105,3 @@ view input =
, _out_edit = edit
, _out_delete = delete
}
-
-getRange :: forall a. Int -> Int -> [a] -> [a]
-getRange perPage currentPage =
- take perPage . drop ((currentPage - 1) * perPage)