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) ] ]