aboutsummaryrefslogtreecommitdiff
path: root/src/Page.purs
blob: 07372d22847a6465e6e3c0d770a22e83ec367ee5 (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
74
75
76
module Page where

import Data.Array ((:), sortBy)
import Data.Maybe (Maybe(..))
import Halogen as H
import Halogen.HTML as HH
import Halogen.HTML.Properties as HP
import Prelude

import Food (Aliment)
import Food as Food
import Format as Format
import Indicator as Indicator

data Query a = NoOp a
type State = Unit
type Message = Unit

component :: forall m . H.Component HH.HTML Query State Message m
component =
  H.component
    { initialState: const unit
    , render
    , eval
    , receiver: const Nothing
    }
  where
    render :: State -> H.ComponentHTML Query
    render state =
      HH.div
        []
        [ HH.h1 [] [ HH.text "Glycémie" ]
        , HH.ul
            [ HP.class_ $ HH.ClassName "aliments" ]
            (renderTitle : (map renderAliment <<< sortBy (\a b -> compare a.name b.name) $ Food.all))
        ]

    eval :: Query ~> H.ComponentDSL State Query Message m
    eval = case _ of
      NoOp next -> pure next

renderTitle :: H.ComponentHTML Query
renderTitle =
  HH.li
    [ HP.class_ $ HH.ClassName "title" ]
    [ HH.div
        []
        [ HH.text "Aliment" ]
    , HH.div
        []
        [ HH.text "Index glycémique" ]
    , HH.div
        []
        [ HH.text "Glucides pour 100 g" ]
    , HH.div
        []
        [ HH.text "Charge glycémique" ]
    ]

renderAliment :: Aliment -> H.ComponentHTML Query
renderAliment aliment =
  HH.li
    []
    [ HH.div
        []
        [ HH.text aliment.name ]
    , HH.div
        [ HP.class_ $ HH.ClassName ("number " <> (show $ Indicator.fromGlycemicIndex aliment.glycemicIndex)) ]
        [ HH.text (show aliment.glycemicIndex) ]
    , HH.div
        [ HP.class_ $ HH.ClassName "number" ]
        [ HH.text (show aliment.carbohydrates) ]
    , HH.div
        [ HP.class_ $ HH.ClassName "number" ]
        [ HH.text (Format.number 2 <<< Food.glycemicLoad $ aliment) ]
    ]