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.hs19
-rw-r--r--client/src/View/Income/Form.hs83
-rw-r--r--client/src/View/Income/Header.hs43
-rw-r--r--client/src/View/Income/Income.hs34
-rw-r--r--client/src/View/Income/Table.hs29
5 files changed, 101 insertions, 107 deletions
diff --git a/client/src/View/Income/Add.hs b/client/src/View/Income/Add.hs
index 0b1bd04..f8f107f 100644
--- a/client/src/View/Income/Add.hs
+++ b/client/src/View/Income/Add.hs
@@ -13,7 +13,6 @@ import qualified Common.Util.Time as TimeUtil
import qualified Component.Modal as Modal
import qualified Util.Ajax as Ajax
import qualified Util.Reflex as ReflexUtil
-import View.Income.Form (FormIn (..), FormOut (..))
import qualified View.Income.Form as Form
view :: forall t m. MonadWidget t m => Modal.Content t m Income
@@ -22,16 +21,16 @@ view cancel = do
currentDay <- liftIO $ Time.getCurrentTime >>= TimeUtil.timeToDay
form <- R.dyn $
- return $ Form.view $ FormIn
- { _formIn_cancel = cancel
- , _formIn_headerLabel = Msg.get Msg.Income_AddLong
- , _formIn_amount = ""
- , _formIn_date = currentDay
- , _formIn_mkPayload = CreateIncomeForm
- , _formIn_ajax = Ajax.post
+ return $ Form.view $ Form.In
+ { Form._in_cancel = cancel
+ , Form._in_headerLabel = Msg.get Msg.Income_AddLong
+ , Form._in_amount = ""
+ , Form._in_date = currentDay
+ , Form._in_mkPayload = CreateIncomeForm
+ , Form._in_ajax = Ajax.post
}
- hide <- ReflexUtil.flatten (_formOut_hide <$> form)
- addIncome <- ReflexUtil.flatten (_formOut_addIncome <$> form)
+ hide <- ReflexUtil.flatten (Form._out_hide <$> form)
+ addIncome <- ReflexUtil.flatten (Form._out_addIncome <$> form)
return (hide, addIncome)
diff --git a/client/src/View/Income/Form.hs b/client/src/View/Income/Form.hs
index 824bb0a..917edf1 100644
--- a/client/src/View/Income/Form.hs
+++ b/client/src/View/Income/Form.hs
@@ -1,7 +1,7 @@
module View.Income.Form
( view
- , FormIn(..)
- , FormOut(..)
+ , In(..)
+ , Out(..)
) where
import Data.Aeson (FromJSON, ToJSON)
@@ -17,42 +17,41 @@ import qualified Reflex.Dom as R
import Common.Model (Income)
import qualified Common.Msg as Msg
import qualified Common.Validation.Income as IncomeValidation
-import Component (InputIn (..), InputOut (..),
- ModalFormIn (..), ModalFormOut (..))
-import qualified Component as Component
+import qualified Component.Input as Input
+import qualified Component.ModalForm as ModalForm
-data FormIn m t a = FormIn
- { _formIn_cancel :: Event t ()
- , _formIn_headerLabel :: Text
- , _formIn_amount :: Text
- , _formIn_date :: Day
- , _formIn_mkPayload :: Text -> Text -> a
- , _formIn_ajax :: Text -> Event t a -> m (Event t (Either Text Income))
+data In m t a = In
+ { _in_cancel :: Event t ()
+ , _in_headerLabel :: Text
+ , _in_amount :: Text
+ , _in_date :: Day
+ , _in_mkPayload :: Text -> Text -> a
+ , _in_ajax :: Text -> Event t a -> m (Event t (Either Text Income))
}
-data FormOut t = FormOut
- { _formOut_hide :: Event t ()
- , _formOut_addIncome :: Event t Income
+data Out t = Out
+ { _out_hide :: Event t ()
+ , _out_addIncome :: Event t Income
}
-view :: forall t m a. (MonadWidget t m, ToJSON a) => FormIn m t a -> m (FormOut t)
-view formIn = do
+view :: forall t m a. (MonadWidget t m, ToJSON a) => In m t a -> m (Out t)
+view input = do
rec
let reset = R.leftmost
- [ "" <$ _modalFormOut_cancel modalForm
- , "" <$ _modalFormOut_validate modalForm
- , "" <$ _formIn_cancel formIn
+ [ "" <$ ModalForm._out_cancel modalForm
+ , "" <$ ModalForm._out_validate modalForm
+ , "" <$ _in_cancel input
]
- modalForm <- Component.modalForm $ ModalFormIn
- { _modalFormIn_headerLabel = _formIn_headerLabel formIn
- , _modalFormIn_ajax = _formIn_ajax formIn "/api/income"
- , _modalFormIn_form = form reset (_modalFormOut_confirm modalForm)
+ modalForm <- ModalForm.view $ ModalForm.In
+ { ModalForm._in_headerLabel = _in_headerLabel input
+ , ModalForm._in_ajax = _in_ajax input "/api/income"
+ , ModalForm._in_form = form reset (ModalForm._out_confirm modalForm)
}
- return $ FormOut
- { _formOut_hide = _modalFormOut_hide modalForm
- , _formOut_addIncome = _modalFormOut_validate modalForm
+ return $ Out
+ { _out_hide = ModalForm._out_hide modalForm
+ , _out_addIncome = ModalForm._out_validate modalForm
}
where
@@ -61,24 +60,24 @@ view formIn = do
-> Event t ()
-> m (Dynamic t (Validation Text a))
form reset confirm = do
- amount <- _inputOut_raw <$> (Component.input
- (Component.defaultInputIn
- { _inputIn_label = Msg.get Msg.Income_Amount
- , _inputIn_initialValue = _formIn_amount formIn
- , _inputIn_validation = IncomeValidation.amount
+ amount <- Input._out_raw <$> (Input.view
+ (Input.defaultIn
+ { Input._in_label = Msg.get Msg.Income_Amount
+ , Input._in_initialValue = _in_amount input
+ , Input._in_validation = IncomeValidation.amount
})
- (_formIn_amount formIn <$ reset)
+ (_in_amount input <$ reset)
confirm)
- let initialDate = T.pack . Calendar.showGregorian . _formIn_date $ formIn
+ let initialDate = T.pack . Calendar.showGregorian . _in_date $ input
- date <- _inputOut_raw <$> (Component.input
- (Component.defaultInputIn
- { _inputIn_label = Msg.get Msg.Income_Date
- , _inputIn_initialValue = initialDate
- , _inputIn_inputType = "date"
- , _inputIn_hasResetButton = False
- , _inputIn_validation = IncomeValidation.date
+ date <- Input._out_raw <$> (Input.view
+ (Input.defaultIn
+ { Input._in_label = Msg.get Msg.Income_Date
+ , Input._in_initialValue = initialDate
+ , Input._in_inputType = "date"
+ , Input._in_hasResetButton = False
+ , Input._in_validation = IncomeValidation.date
})
(initialDate <$ reset)
confirm)
@@ -86,4 +85,4 @@ view formIn = do
return $ do
a <- amount
d <- date
- return . V.Success $ (_formIn_mkPayload formIn) a d
+ return . V.Success $ (_in_mkPayload input) a d
diff --git a/client/src/View/Income/Header.hs b/client/src/View/Income/Header.hs
index 4e08955..ae1174a 100644
--- a/client/src/View/Income/Header.hs
+++ b/client/src/View/Income/Header.hs
@@ -1,7 +1,7 @@
module View.Income.Header
( view
- , HeaderIn(..)
- , HeaderOut(..)
+ , In(..)
+ , Out(..)
) where
import Control.Monad.IO.Class (liftIO)
@@ -16,25 +16,24 @@ import qualified Common.Model as CM
import qualified Common.Msg as Msg
import qualified Common.View.Format as Format
-import Component (ButtonOut (..))
-import qualified Component
+import qualified Component.Button as Button
import qualified Component.Modal as Modal
import qualified Util.Date as DateUtil
import qualified View.Income.Add as Add
import View.Income.Init (Init (..))
-data HeaderIn t = HeaderIn
- { _headerIn_init :: Init
- , _headerIn_currency :: Currency
- , _headerIn_incomes :: Dynamic t [Income]
+data In t = In
+ { _in_init :: Init
+ , _in_currency :: Currency
+ , _in_incomes :: Dynamic t [Income]
}
-data HeaderOut t = HeaderOut
- { _headerOut_addIncome :: Event t Income
+data Out t = Out
+ { _out_addIncome :: Event t Income
}
-view :: forall t m. MonadWidget t m => HeaderIn t -> m (HeaderOut t)
-view headerIn =
+view :: forall t m. MonadWidget t m => In t -> m (Out t)
+view input =
R.divClass "withMargin" $ do
currentTime <- liftIO Clock.getCurrentTime
@@ -58,7 +57,7 @@ view headerIn =
T.intercalate " "
[ _user_name user
, "−"
- , Format.price (_headerIn_currency headerIn) $
+ , Format.price (_in_currency input) $
CM.cumulativeIncomesSince currentTime since userIncomes
]
@@ -67,23 +66,23 @@ view headerIn =
R.text $
Msg.get Msg.Income_MonthlyNet
- addIncome <- _buttonOut_clic <$>
- (Component.button . Component.defaultButtonIn . R.text $
+ addIncome <- Button._out_clic <$>
+ (Button.view . Button.defaultIn . R.text $
Msg.get Msg.Income_AddLong)
- addIncome <- Modal.view $ Modal.Input
- { Modal._input_show = addIncome
- , Modal._input_content = Add.view
+ addIncome <- Modal.view $ Modal.In
+ { Modal._in_show = addIncome
+ , Modal._in_content = Add.view
}
- return $ HeaderOut
- { _headerOut_addIncome = addIncome
+ return $ Out
+ { _out_addIncome = addIncome
}
where
- init = _headerIn_init headerIn
+ init = _in_init input
- useIncomesFrom = R.ffor (_headerIn_incomes headerIn) $ \incomes ->
+ useIncomesFrom = R.ffor (_in_incomes input) $ \incomes ->
( CM.useIncomesFrom
(map _user_id $_init_users init)
incomes
diff --git a/client/src/View/Income/Income.hs b/client/src/View/Income/Income.hs
index 18ebe7c..f8359bb 100644
--- a/client/src/View/Income/Income.hs
+++ b/client/src/View/Income/Income.hs
@@ -1,7 +1,7 @@
module View.Income.Income
( init
, view
- , IncomeIn(..)
+ , In(..)
) where
import Data.Aeson (FromJSON)
@@ -14,15 +14,13 @@ import Common.Model (Currency)
import Loadable (Loadable (..))
import qualified Loadable
import qualified Util.Ajax as AjaxUtil
-import View.Income.Header (HeaderIn (..), HeaderOut (..))
import qualified View.Income.Header as Header
import View.Income.Init (Init (..))
-import View.Income.Table (IncomeTableIn (..))
import qualified View.Income.Table as Table
-data IncomeIn t = IncomeIn
- { _incomeIn_currency :: Currency
- , _incomeIn_init :: Dynamic t (Loadable Init)
+data In t = In
+ { _in_currency :: Currency
+ , _in_init :: Dynamic t (Loadable Init)
}
init :: forall t m. MonadWidget t m => m (Dynamic t (Loadable Init))
@@ -36,9 +34,9 @@ init = do
ps <- payments
return $ Init <$> us <*> is <*> ps
-view :: forall t m. MonadWidget t m => IncomeIn t -> m ()
-view incomeIn = do
- R.dyn . R.ffor (_incomeIn_init incomeIn) . Loadable.view $ \init ->
+view :: forall t m. MonadWidget t m => In t -> m ()
+view input = do
+ R.dyn . R.ffor (_in_init input) . Loadable.view $ \init ->
R.elClass "main" "income" $ do
@@ -47,18 +45,18 @@ view incomeIn = do
incomes <- R.foldDyn
(:)
(_init_incomes init)
- (_headerOut_addIncome header)
+ (Header._out_addIncome header)
- header <- Header.view $ HeaderIn
- { _headerIn_init = init
- , _headerIn_currency = _incomeIn_currency incomeIn
- , _headerIn_incomes = incomes
+ header <- Header.view $ Header.In
+ { Header._in_init = init
+ , Header._in_currency = _in_currency input
+ , Header._in_incomes = incomes
}
- Table.view $ IncomeTableIn
- { _tableIn_init = init
- , _tableIn_currency = _incomeIn_currency incomeIn
- , _tableIn_incomes = incomes
+ 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 d42848b..9cb705f 100644
--- a/client/src/View/Income/Table.hs
+++ b/client/src/View/Income/Table.hs
@@ -1,6 +1,6 @@
module View.Income.Table
( view
- , IncomeTableIn(..)
+ , In(..)
) where
import qualified Data.List as L
@@ -14,25 +14,24 @@ import qualified Common.Model as CM
import qualified Common.Msg as Msg
import qualified Common.View.Format as Format
-import Component (TableIn (..))
-import qualified Component
+import qualified Component.Table as Table
import View.Income.Init (Init (..))
-data IncomeTableIn t = IncomeTableIn
- { _tableIn_init :: Init
- , _tableIn_currency :: Currency
- , _tableIn_incomes :: Dynamic t [Income]
+data In t = In
+ { _in_init :: Init
+ , _in_currency :: Currency
+ , _in_incomes :: Dynamic t [Income]
}
-view :: forall t m. MonadWidget t m => IncomeTableIn t -> m ()
-view tableIn = do
+view :: forall t m. MonadWidget t m => In t -> m ()
+view input = do
- Component.table $ TableIn
- { _tableIn_headerLabel = headerLabel
- , _tableIn_rows = R.ffor (_tableIn_incomes tableIn) $ reverse . L.sortOn _income_date
- , _tableIn_cell = cell (_tableIn_init tableIn) (_tableIn_currency tableIn)
- , _tableIn_perPage = 7
- , _tableIn_resetPage = R.never
+ 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
}
return ()