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
92
|
module View.Income.Header
( view
, HeaderIn(..)
, HeaderOut(..)
) 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 Component (ButtonOut (..))
import qualified Component
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 HeaderOut t = HeaderOut
{ _headerOut_addIncome :: Event t Income
}
view :: forall t m. MonadWidget t m => HeaderIn t -> m (HeaderOut t)
view headerIn =
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 (_headerIn_currency headerIn) $
CM.cumulativeIncomesSince currentTime since userIncomes
]
R.divClass "titleButton" $ do
R.el "h1" $
R.text $
Msg.get Msg.Income_MonthlyNet
addIncome <- _buttonOut_clic <$>
(Component.button . Component.defaultButtonIn . R.text $
Msg.get Msg.Income_AddLong)
addIncome <- Modal.view $ Modal.Input
{ Modal._input_show = addIncome
, Modal._input_content = Add.view
}
return $ HeaderOut
{ _headerOut_addIncome = addIncome
}
where
init = _headerIn_init headerIn
useIncomesFrom = R.ffor (_headerIn_incomes headerIn) $ \incomes ->
( CM.useIncomesFrom
(map _user_id $_init_users init)
incomes
(_init_payments init)
, incomes
)
|