blob: bf765665a32e0cbe77ad7f74d4eb9a614c5f1838 (
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
|
module Component.Table
( view
, In(..)
, Out(..)
) where
import Data.Text (Text)
import Reflex.Dom (Dynamic, Event, MonadWidget)
import qualified Reflex.Dom as R
import qualified Component.Pages as Pages
data In h r t = In
{ _in_headerLabel :: h -> Text
, _in_rows :: Dynamic t [r]
, _in_cell :: h -> r -> Text
, _in_perPage :: Int
, _in_resetPage :: Event t ()
}
data Out = Out
{}
view :: forall t m h r. (MonadWidget t m, Bounded h, Enum h) => In h r t -> m (Out)
view input =
R.divClass "table" $ do
rec
R.divClass "lines" $ do
R.divClass "header" $
flip mapM_ [minBound..] $ \header ->
R.divClass "cell" . R.text $
_in_headerLabel input header
let rows = getRange
(_in_perPage input)
<$> (Pages._out_currentPage pages)
<*> (_in_rows input)
R.simpleList rows $ \r ->
R.divClass "row" $
flip mapM_ [minBound..] $ \h ->
R.divClass "cell name" $
R.dynText $
R.ffor r (_in_cell input h)
pages <- Pages.view $ Pages.In
{ Pages._in_total = length <$> (_in_rows input)
, Pages._in_perPage = _in_perPage input
, Pages._in_reset = _in_resetPage input
}
return ()
return $ Out
{}
getRange :: forall a. Int -> Int -> [a] -> [a]
getRange perPage currentPage =
take perPage . drop ((currentPage - 1) * perPage)
|