aboutsummaryrefslogtreecommitdiff
path: root/client/src/View/Income
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/View/Income')
-rw-r--r--client/src/View/Income/Add.hs20
-rw-r--r--client/src/View/Income/Header.hs2
-rw-r--r--client/src/View/Income/Income.hs17
-rw-r--r--client/src/View/Income/Table.hs32
4 files changed, 47 insertions, 24 deletions
diff --git a/client/src/View/Income/Add.hs b/client/src/View/Income/Add.hs
index f8f107f..d07bd45 100644
--- a/client/src/View/Income/Add.hs
+++ b/client/src/View/Income/Add.hs
@@ -1,13 +1,16 @@
module View.Income.Add
( view
+ , In(..)
) where
import Control.Monad.IO.Class (liftIO)
+import qualified Data.Maybe as Maybe
+import qualified Data.Text as T
import qualified Data.Time.Clock as Time
-import Reflex.Dom (MonadWidget)
+import Reflex.Dom (Dynamic, MonadWidget)
import qualified Reflex.Dom as R
-import Common.Model (CreateIncomeForm (..), Income)
+import Common.Model (CreateIncomeForm (..), Income (..))
import qualified Common.Msg as Msg
import qualified Common.Util.Time as TimeUtil
import qualified Component.Modal as Modal
@@ -15,16 +18,21 @@ import qualified Util.Ajax as Ajax
import qualified Util.Reflex as ReflexUtil
import qualified View.Income.Form as Form
-view :: forall t m. MonadWidget t m => Modal.Content t m Income
-view cancel = do
+data In t = In
+ { _in_income :: Dynamic t (Maybe Income)
+ }
+
+view :: forall t m. MonadWidget t m => In t -> Modal.Content t m Income
+view input cancel = do
currentDay <- liftIO $ Time.getCurrentTime >>= TimeUtil.timeToDay
- form <- R.dyn $
+ form <- R.dyn $ do
+ income <- _in_income input
return $ Form.view $ Form.In
{ Form._in_cancel = cancel
, Form._in_headerLabel = Msg.get Msg.Income_AddLong
- , Form._in_amount = ""
+ , Form._in_amount = Maybe.fromMaybe "" ((T.pack . show . _income_amount) <$> income)
, Form._in_date = currentDay
, Form._in_mkPayload = CreateIncomeForm
, Form._in_ajax = Ajax.post
diff --git a/client/src/View/Income/Header.hs b/client/src/View/Income/Header.hs
index ae1174a..0360d1f 100644
--- a/client/src/View/Income/Header.hs
+++ b/client/src/View/Income/Header.hs
@@ -72,7 +72,7 @@ view input =
addIncome <- Modal.view $ Modal.In
{ Modal._in_show = addIncome
- , Modal._in_content = Add.view
+ , Modal._in_content = Add.view $ Add.In { Add._in_income = R.constDyn Nothing }
}
return $ Out
diff --git a/client/src/View/Income/Income.hs b/client/src/View/Income/Income.hs
index f8359bb..b97613d 100644
--- a/client/src/View/Income/Income.hs
+++ b/client/src/View/Income/Income.hs
@@ -41,11 +41,14 @@ view input = do
R.elClass "main" "income" $ do
rec
-
+ let addIncome = R.leftmost
+ [ Header._out_addIncome header
+ , Table._out_addIncome table
+ ]
incomes <- R.foldDyn
(:)
(_init_incomes init)
- (Header._out_addIncome header)
+ addIncome
header <- Header.view $ Header.In
{ Header._in_init = init
@@ -53,11 +56,11 @@ view input = do
, Header._in_incomes = incomes
}
- Table.view $ Table.In
- { Table._in_init = init
- , Table._in_currency = _in_currency input
- , Table._in_incomes = incomes
- }
+ table <- Table.view $ Table.In
+ { Table._in_init = init
+ , Table._in_currency = _in_currency input
+ , Table._in_incomes = incomes
+ }
return ()
diff --git a/client/src/View/Income/Table.hs b/client/src/View/Income/Table.hs
index 9cb705f..358cb17 100644
--- a/client/src/View/Income/Table.hs
+++ b/client/src/View/Income/Table.hs
@@ -1,12 +1,13 @@
module View.Income.Table
( view
, In(..)
+ , Out(..)
) where
import qualified Data.List as L
import qualified Data.Maybe as Maybe
import Data.Text (Text)
-import Reflex.Dom (Dynamic, MonadWidget)
+import Reflex.Dom (Dynamic, Event, MonadWidget)
import qualified Reflex.Dom as R
import Common.Model (Currency, Income (..), User (..))
@@ -15,6 +16,7 @@ import qualified Common.Msg as Msg
import qualified Common.View.Format as Format
import qualified Component.Table as Table
+import qualified View.Income.Add as Add
import View.Income.Init (Init (..))
data In t = In
@@ -23,18 +25,28 @@ data In t = In
, _in_incomes :: Dynamic t [Income]
}
-view :: forall t m. MonadWidget t m => In t -> m ()
+data Out t = Out
+ { _out_addIncome :: Event t Income
+ }
+
+view :: forall t m. MonadWidget t m => In t -> m (Out t)
view input = do
- Table.view $ Table.In
- { Table._in_headerLabel = headerLabel
- , Table._in_rows = R.ffor (_in_incomes input) $ reverse . L.sortOn _income_date
- , Table._in_cell = cell (_in_init input) (_in_currency input)
- , Table._in_perPage = 7
- , Table._in_resetPage = R.never
- }
+ table <- Table.view $ Table.In
+ { Table._in_headerLabel = headerLabel
+ , Table._in_rows = R.ffor (_in_incomes input) $ reverse . L.sortOn _income_date
+ , Table._in_cell = cell (_in_init input) (_in_currency input)
+ , Table._in_perPage = 7
+ , Table._in_resetPage = R.never
+ , Table._in_cloneModal = \income ->
+ Add.view $ Add.In
+ { Add._in_income = Just <$> income
+ }
+ }
- return ()
+ return $ Out
+ { _out_addIncome = Table._out_add table
+ }
data Header
= UserHeader