aboutsummaryrefslogtreecommitdiff
path: root/client/src/Component
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/Component')
-rw-r--r--client/src/Component/Pages.hs22
-rw-r--r--client/src/Component/Table.hs62
2 files changed, 39 insertions, 45 deletions
diff --git a/client/src/Component/Pages.hs b/client/src/Component/Pages.hs
index a297222..d54cd3d 100644
--- a/client/src/Component/Pages.hs
+++ b/client/src/Component/Pages.hs
@@ -16,32 +16,26 @@ import qualified View.Icon as Icon
data In t = In
{ _in_total :: Dynamic t Int
, _in_perPage :: Int
+ , _in_page :: Int
}
data Out t = Out
{ _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
- (newPage, currentPage) <- ReflexUtil.divVisibleIf ((> 0) <$> total) $ pageButtons total perPage
+ newPage <- ReflexUtil.divVisibleIf ((> 0) <$> (_in_total input)) $ pageButtons input
return $ Out
{ _out_newPage = newPage
- , _out_currentPage = currentPage
}
- where
- total = _in_total input
- perPage = _in_perPage input
-
pageButtons
:: forall t m. MonadWidget t m
- => Dynamic t Int
- -> Int
- -> m (Event t Int, Dynamic t Int)
-pageButtons total perPage = do
+ => In t
+ -> m (Event t Int)
+pageButtons input = do
R.divClass "pages" $ do
rec
let newPage = R.leftmost
@@ -52,7 +46,7 @@ pageButtons total perPage = do
, lastPageClic
]
- currentPage <- R.holdDyn 1 newPage
+ currentPage <- R.holdDyn (_in_page input) newPage
firstPageClic <- pageButton noCurrentPage (R.constDyn 1) Icon.doubleLeftBar
@@ -65,9 +59,9 @@ pageButtons total perPage = do
lastPageClic <- pageButton noCurrentPage maxPage Icon.doubleRightBar
- return (newPage, currentPage)
+ return newPage
- where maxPage = R.ffor total (\t -> ceiling $ toRational t / toRational perPage)
+ where maxPage = R.ffor (_in_total input) (\t -> ceiling $ toRational t / toRational (_in_perPage input))
pageEvent = R.switch . R.current . fmap R.leftmost
noCurrentPage = R.constDyn Nothing
diff --git a/client/src/Component/Table.hs b/client/src/Component/Table.hs
index 7103abd..3b9ec24 100644
--- a/client/src/Component/Table.hs
+++ b/client/src/Component/Table.hs
@@ -4,8 +4,9 @@ module Component.Table
, Out(..)
) where
+import qualified Data.Map as M
import Data.Text (Text)
-import Reflex.Dom (Dynamic, Event, MonadWidget)
+import Reflex.Dom (Event, MonadWidget)
import qualified Reflex.Dom as R
import qualified Component.Button as Button
@@ -15,7 +16,7 @@ import qualified View.Icon as Icon
data In m t h r a = In
{ _in_headerLabel :: h -> Text
- , _in_rows :: Dynamic t [r]
+ , _in_rows :: [r]
, _in_cell :: h -> r -> Text
, _in_cloneModal :: r -> Modal.Content t m a
, _in_editModal :: r -> Modal.Content t m a
@@ -44,61 +45,60 @@ view input =
R.divClass "cell" $ R.blank
R.divClass "cell" $ R.blank
- R.simpleList (_in_rows input) $ \r ->
+ flip mapM (_in_rows input) $ \row ->
R.divClass "row" $ do
- flip mapM_ [minBound..] $ \h ->
+ flip mapM_ [minBound..] $ \header ->
R.divClass "cell" $
- R.dynText $
- R.ffor r (_in_cell input h)
+ R.text $
+ _in_cell input header row
- clone <-
+ cloneButton <-
R.divClass "cell button" $
Button._out_clic <$> (Button.view $
Button.defaultIn Icon.clone)
- cloned <-
+ clone <-
Modal.view $ Modal.In
- { Modal._in_show = clone
- , Modal._in_content = \curtainClick ->
- (R.dyn . R.ffor r $ \r2 -> _in_cloneModal input r2 curtainClick)
- >>= ReflexUtil.flattenTuple
+ { Modal._in_show = cloneButton
+ , Modal._in_content = _in_cloneModal input row
}
- let isOwner = R.ffor r (_in_isOwner input)
+ let isOwner = _in_isOwner input row
- edit <-
+ let visibleIf cond =
+ R.elAttr
+ "div"
+ (if cond then M.empty else M.singleton "style" "display:none")
+
+ editButton <-
R.divClass "cell button" $
- ReflexUtil.divVisibleIf isOwner $
+ visibleIf isOwner $
Button._out_clic <$> (Button.view $
Button.defaultIn Icon.edit)
- edited <-
+ edit <-
Modal.view $ Modal.In
- { Modal._in_show = edit
- , Modal._in_content = \curtainClick ->
- (R.dyn . R.ffor r $ \r2 -> _in_editModal input r2 curtainClick)
- >>= ReflexUtil.flattenTuple
+ { Modal._in_show = editButton
+ , Modal._in_content = _in_editModal input row
}
- delete <-
+ deleteButton <-
R.divClass "cell button" $
- ReflexUtil.divVisibleIf isOwner $
+ visibleIf isOwner $
Button._out_clic <$> (Button.view $
Button.defaultIn Icon.delete)
- deleted <-
+ delete <-
Modal.view $ Modal.In
- { Modal._in_show = delete
- , Modal._in_content = \curtainClick ->
- (R.dyn . R.ffor r $ \r2 -> _in_deleteModal input r2 curtainClick)
- >>= ReflexUtil.flattenTuple
+ { Modal._in_show = deleteButton
+ , Modal._in_content = _in_deleteModal input row
}
- return (cloned, edited, deleted)
+ return (clone, edit, delete)
- 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
+ let add = R.leftmost . map (\(a, _, _) -> a) $ result
+ edit = R.leftmost . map (\(_, a, _) -> a) $ result
+ delete = R.leftmost . map (\(_, _, a) -> a) $ result
return $ Out
{ _out_add = add