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
|
module View.Income.Table
( view
, In(..)
) where
import qualified Data.List as L
import qualified Data.Maybe as Maybe
import Data.Text (Text)
import Reflex.Dom (Dynamic, 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.Table as Table
import View.Income.Init (Init (..))
data In t = In
{ _in_init :: Init
, _in_currency :: Currency
, _in_incomes :: Dynamic t [Income]
}
view :: forall t m. MonadWidget t m => In t -> m ()
view input = do
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 ()
data Header
= UserHeader
| AmountHeader
| DateHeader
deriving (Eq, Show, Bounded, Enum)
headerLabel :: Header -> Text
headerLabel UserHeader = Msg.get Msg.Income_Name
headerLabel DateHeader = Msg.get Msg.Income_Date
headerLabel AmountHeader = Msg.get Msg.Income_Amount
cell :: Init -> Currency -> Header -> Income -> Text
cell init currency header income =
case header of
UserHeader ->
Maybe.fromMaybe "" . fmap _user_name $ CM.findUser (_income_userId income) (_init_users init)
DateHeader ->
Format.longDay . _income_date $ income
AmountHeader ->
Format.price currency . _income_amount $ income
|