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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
module View.Income.Header
( view
, In(..)
, Out(..)
) 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 Clock
import Reflex.Dom (Dynamic, Event, MonadWidget)
import qualified Reflex.Dom as R
import Common.Model (Currency, Income (..), User (..))
import qualified Common.Model as CM
import qualified Common.Msg as Msg
import qualified Common.View.Format as Format
import qualified Component.Button as Button
import qualified Component.Modal as Modal
import qualified Util.Date as DateUtil
import qualified View.Income.Form as Form
import View.Income.Init (Init (..))
data In t = In
{ _in_init :: Init
, _in_currency :: Currency
, _in_incomes :: Dynamic t [Income]
}
data Out t = Out
{ _out_add :: Event t Income
}
view :: forall t m. MonadWidget t m => In t -> m (Out t)
view input =
R.divClass "withMargin" $ do
currentTime <- liftIO Clock.getCurrentTime
R.dyn . R.ffor useIncomesFrom $ \case
(Nothing, _) ->
R.blank
(Just since, incomes) ->
R.el "div" $ do
R.el "h1" $ do
day <- liftIO $ DateUtil.utcToLocalDay since
R.text $ Msg.get (Msg.Income_CumulativeSince (Format.longDay day))
R.el "ul" $
flip mapM_ (_init_users init) $ \user ->
R.el "li" $
R.text $ do
let userIncomes = filter ((==) (_user_id user) . _income_userId) incomes
T.intercalate " "
[ _user_name user
, "−"
, Format.price (_in_currency input) $
CM.cumulativeIncomesSince currentTime since userIncomes
]
R.divClass "titleButton" $ do
R.el "h1" $
R.text $
Msg.get Msg.Income_MonthlyNet
addIncome <- Button._out_clic <$>
(Button.view . Button.defaultIn . R.text $
Msg.get Msg.Income_AddLong)
addIncome <- Modal.view $ Modal.In
{ Modal._in_show = addIncome
, Modal._in_content = Form.view $ Form.In { Form._in_operation = Form.New }
}
return $ Out
{ _out_add = addIncome
}
where
init = _in_init input
useIncomesFrom = R.ffor (_in_incomes input) $ \incomes ->
( CM.useIncomesFrom
(map _user_id $_init_users init)
incomes
(_init_payments init)
, incomes
)
|