aboutsummaryrefslogtreecommitdiff
path: root/client/src/Component/Table.hs
diff options
context:
space:
mode:
authorJoris2019-10-23 21:09:54 +0200
committerJoris2019-10-23 21:11:11 +0200
commitf968c8ce63e1aec119b1e6f414cf27e2c0294bcb (patch)
treeab539d6d1618ad724498f5ad3954f74409f65383 /client/src/Component/Table.hs
parent61ff1443c42def5a09f624e3df2e2520e97610d0 (diff)
downloadbudget-f968c8ce63e1aec119b1e6f414cf27e2c0294bcb.tar.gz
budget-f968c8ce63e1aec119b1e6f414cf27e2c0294bcb.tar.bz2
budget-f968c8ce63e1aec119b1e6f414cf27e2c0294bcb.zip
Delete income
Diffstat (limited to 'client/src/Component/Table.hs')
-rw-r--r--client/src/Component/Table.hs42
1 files changed, 31 insertions, 11 deletions
diff --git a/client/src/Component/Table.hs b/client/src/Component/Table.hs
index 5819f45..b3c70a0 100644
--- a/client/src/Component/Table.hs
+++ b/client/src/Component/Table.hs
@@ -20,11 +20,14 @@ data In m t h r a = In
, _in_cell :: h -> r -> Text
, _in_perPage :: Int
, _in_resetPage :: Event t ()
- , _in_cloneModal :: Dynamic t r -> Modal.Content t m a
+ , _in_cloneModal :: r -> Modal.Content t m a
+ , _in_deleteModal :: r -> Modal.Content t m a
+ , _in_isOwner :: r -> Bool
}
data Out t a = Out
- { _out_add :: Event t a
+ { _out_add :: Event t a
+ , _out_delete :: Event t a
}
view :: forall t m h r a. (MonadWidget t m, Bounded h, Enum h) => In m t h r a -> m (Out t a)
@@ -39,6 +42,7 @@ view input =
_in_headerLabel input header
R.divClass "cell" $ R.blank
+ R.divClass "cell" $ R.blank
let rows = getRange
(_in_perPage input)
@@ -60,25 +64,41 @@ view input =
cloned <-
Modal.view $ Modal.In
{ Modal._in_show = clone
- , Modal._in_content = _in_cloneModal input r
+ , Modal._in_content = \curtainClick ->
+ (R.dyn . R.ffor r $ \r2 -> _in_cloneModal input r2 curtainClick)
+ >>= ReflexUtil.flattenTuple
+ }
+
+ let isOwner = R.ffor r (_in_isOwner input)
+
+ delete <-
+ R.divClass "cell button" $
+ ReflexUtil.divVisibleIf isOwner $
+ Button._out_clic <$> (Button.view $
+ Button.defaultIn Icon.delete)
+
+ deleted <-
+ 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
}
- return cloned
+ return (cloned, deleted)
pages <- Pages.view $ Pages.In
- { Pages._in_total = length <$> (_in_rows input)
+ { Pages._in_total = length <$> _in_rows input
, Pages._in_perPage = _in_perPage input
, Pages._in_reset = _in_resetPage input
}
- -- return $
- -- ( R.switch . R.current . fmap (R.leftmost . map (\(a, _, _) -> a)) $ result
- -- , R.switch . R.current . fmap (R.leftmost . map (\(_, b, _) -> b)) $ result
- -- , R.switch . R.current . fmap (R.leftmost . map (\(_, _, c) -> c)) $ result
- -- )
+ let add = R.switch . R.current . fmap (R.leftmost . map fst) $ result
+ delete = R.switch . R.current . fmap (R.leftmost . map snd) $ result
return $ Out
- { _out_add = R.switch . R.current . fmap R.leftmost $ result
+ { _out_add = add
+ , _out_delete = delete
}
getRange :: forall a. Int -> Int -> [a] -> [a]