From 28d595fef6d96557c3d318bc63e716dcebba282d Mon Sep 17 00:00:00 2001 From: Joris Date: Wed, 5 Apr 2017 21:26:31 +0200 Subject: Add glycemic index indicator --- .tmuxinator.yml | 1 + public/main.css | 12 ++++++++++++ src/Food.purs | 12 ++++++++---- src/Indicator.purs | 19 +++++++++++++++++++ src/Page.purs | 12 ++++++------ 5 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 src/Indicator.purs diff --git a/.tmuxinator.yml b/.tmuxinator.yml index 914bf4f..6dec166 100644 --- a/.tmuxinator.yml +++ b/.tmuxinator.yml @@ -6,5 +6,6 @@ windows: panes: - # Empty - build: + - fuser -k 9000/tcp - webfsd -r public -f index.html -p 9000 - npm install && bower install && ./watch diff --git a/public/main.css b/public/main.css index 86455a6..0f092cf 100644 --- a/public/main.css +++ b/public/main.css @@ -23,6 +23,18 @@ ul.aliments > li > div { padding: 15px; } +ul.aliments > li > .Good { + color: green; +} + +ul.aliments > li > .Medium { + color: orange; +} + +ul.aliments > li > .Bad { + color: red; +} + ul.aliments > li > .number { text-align: right; } diff --git a/src/Food.purs b/src/Food.purs index b1e3d29..19b667c 100644 --- a/src/Food.purs +++ b/src/Food.purs @@ -18,8 +18,12 @@ glycemicLoad aliment = toNumber aliment.glycemicIndex * toNumber aliment.carbohy all :: Array Aliment all = - [ { name: "oignon", glycemicIndex: 15, carbohydrates: 9 } - , { name: "olive", glycemicIndex: 15, carbohydrates: 6 } - , { name: "haricot rouge", glycemicIndex: 35, carbohydrates: 24 } - , { name: "haricot blanc", glycemicIndex: 35, carbohydrates: 13 } + [ { name: "oignons", glycemicIndex: 15, carbohydrates: 9 } + , { name: "olives", glycemicIndex: 15, carbohydrates: 6 } + , { name: "haricots rouges", glycemicIndex: 35, carbohydrates: 24 } + , { name: "haricots blancs", glycemicIndex: 35, carbohydrates: 13 } + , { name: "pommes de terres (cuites avec leur peau)", glycemicIndex: 70, carbohydrates: 37 } + , { name: "lentilles vertes", glycemicIndex: 30, carbohydrates: 30 } + , { name: "lentilles corail", glycemicIndex: 21, carbohydrates: 48 } + , { name: "riz basmatti", glycemicIndex: 58, carbohydrates: 25 } ] diff --git a/src/Indicator.purs b/src/Indicator.purs new file mode 100644 index 0000000..536133d --- /dev/null +++ b/src/Indicator.purs @@ -0,0 +1,19 @@ +module Indicator + ( Indicator(..) + , fromGlycemicIndex + ) where + +import Prelude + +data Indicator = Good | Medium | Bad + +instance showIndicator :: Show Indicator where + show Good = "Good" + show Medium = "Medium" + show Bad = "Bad" + +fromGlycemicIndex :: Int -> Indicator +fromGlycemicIndex n + | n < 40 = Good + | n < 55 = Medium + | otherwise = Bad diff --git a/src/Page.purs b/src/Page.purs index 76cdf8d..07372d2 100644 --- a/src/Page.purs +++ b/src/Page.purs @@ -1,5 +1,6 @@ module Page where +import Data.Array ((:), sortBy) import Data.Maybe (Maybe(..)) import Halogen as H import Halogen.HTML as HH @@ -9,12 +10,11 @@ import Prelude import Food (Aliment) import Food as Food import Format as Format - -type State = Unit +import Indicator as Indicator data Query a = NoOp a - -data Message = Toggled Boolean +type State = Unit +type Message = Unit component :: forall m . H.Component HH.HTML Query State Message m component = @@ -32,7 +32,7 @@ component = [ HH.h1 [] [ HH.text "Glycémie" ] , HH.ul [ HP.class_ $ HH.ClassName "aliments" ] - ([renderTitle] <> (map renderAliment Food.all)) + (renderTitle : (map renderAliment <<< sortBy (\a b -> compare a.name b.name) $ Food.all)) ] eval :: Query ~> H.ComponentDSL State Query Message m @@ -65,7 +65,7 @@ renderAliment aliment = [] [ HH.text aliment.name ] , HH.div - [ HP.class_ $ HH.ClassName "number" ] + [ HP.class_ $ HH.ClassName ("number " <> (show $ Indicator.fromGlycemicIndex aliment.glycemicIndex)) ] [ HH.text (show aliment.glycemicIndex) ] , HH.div [ HP.class_ $ HH.ClassName "number" ] -- cgit v1.2.3