blob: 91682a06cd20587266803a95835561670e5160fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
module View.Income.Income
( init
, view
, IncomeIn(..)
) where
import Prelude hiding (init)
import Reflex.Dom (Dynamic, MonadWidget)
import qualified Reflex.Dom as R
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 t = IncomeIn
{ _incomeIn_currency :: Currency
, _incomeIn_init :: Dynamic t (Loadable Init)
}
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
incomes <- R.foldDyn
(:)
(_init_incomes init)
(_headerOut_addIncome header)
header <- Header.view $ HeaderIn
{ _headerIn_init = init
, _headerIn_currency = _incomeIn_currency incomeIn
, _headerIn_incomes = incomes
}
Table.view $ IncomeTableIn
{ _tableIn_init = init
, _tableIn_currency = _incomeIn_currency incomeIn
, _tableIn_incomes = incomes
}
return ()
return ()
|