aboutsummaryrefslogtreecommitdiff
path: root/client/src/View/Income/Income.hs
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/View/Income/Income.hs')
-rw-r--r--client/src/View/Income/Income.hs73
1 files changed, 53 insertions, 20 deletions
diff --git a/client/src/View/Income/Income.hs b/client/src/View/Income/Income.hs
index 167aedf..91682a0 100644
--- a/client/src/View/Income/Income.hs
+++ b/client/src/View/Income/Income.hs
@@ -1,40 +1,73 @@
module View.Income.Income
- ( view
+ ( init
+ , view
, IncomeIn(..)
) where
+import Prelude hiding (init)
import Reflex.Dom (Dynamic, MonadWidget)
import qualified Reflex.Dom as R
-import Common.Model (Init (..))
+import Common.Model (Currency)
+
+import Model.Loadable (Loadable (..))
+import qualified Model.Loadable as 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 = IncomeIn
- { _incomeIn_init :: Init
+data IncomeIn t = IncomeIn
+ { _incomeIn_currency :: Currency
+ , _incomeIn_init :: Dynamic t (Loadable Init)
}
-view :: forall t m. MonadWidget t m => IncomeIn -> m ()
-view incomeIn =
- R.elClass "main" "income" $ do
+init :: forall t m. MonadWidget t m => m (Dynamic t (Loadable Init))
+init = do
+ postBuild <- R.getPostBuild
+
+ usersEvent <- AjaxUtil.get (R.tag (R.constant "api/users") postBuild)
+ users <- Loadable.fromEvent usersEvent
+
+ incomesEvent <- AjaxUtil.get (R.tag (R.constant "api/incomes") postBuild)
+ incomes <- Loadable.fromEvent incomesEvent
+
+ paymentsEvent <- AjaxUtil.get (R.tag (R.constant "api/payments") postBuild)
+ payments <- Loadable.fromEvent paymentsEvent
+
+ return $ do
+ us <- users
+ is <- incomes
+ 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 ->
+
+ R.elClass "main" "income" $ do
+
+ rec
- rec
+ incomes <- R.foldDyn
+ (:)
+ (_init_incomes init)
+ (_headerOut_addIncome header)
- incomes <- R.foldDyn
- (:)
- (_init_incomes . _incomeIn_init $ incomeIn)
- (_headerOut_addIncome header)
+ header <- Header.view $ HeaderIn
+ { _headerIn_init = init
+ , _headerIn_currency = _incomeIn_currency incomeIn
+ , _headerIn_incomes = incomes
+ }
- header <- Header.view $ HeaderIn
- { _headerIn_init = _incomeIn_init incomeIn
- , _headerIn_incomes = incomes
+ Table.view $ IncomeTableIn
+ { _tableIn_init = init
+ , _tableIn_currency = _incomeIn_currency incomeIn
+ , _tableIn_incomes = incomes
}
- Table.view $ IncomeTableIn
- { _tableIn_init = _incomeIn_init incomeIn
- , _tableIn_incomes = incomes
- }
+ return ()
- return ()
+ return ()