aboutsummaryrefslogtreecommitdiff
path: root/src/View/View.elm
blob: 05006100f0aafbeecdfbdd97807e2c6dd5342e87 (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
module View.View
  ( view
  ) where

import Html (..)
import Html.Attributes (..)
import Html.Events (..)
import Signal
import List
import Dict
import Json.Decode as Json

import Model.Model (..)
import Model.Timer (..)
import Model.Id (..)

import Update.Update (..)

import View.Timer (timerView)

view : Model -> Html
view model =
  div
    []
    [ title
    , model.timers
        |> Dict.toList
        |> List.sortBy (.creationTime << snd)
        |> List.reverse
        |> timers model
    ]

title : Html
title =
  div
    [ class "headerBar" ]
    [ button
        [ onClick (Signal.send updates Initialize)
        , class "title"
        ]
        [ text "Timer" ]
    , button
        [ onClick (Signal.send updates AddNewTimer)
        , class "addTimer"
        ]
        [ i
            [ class "fa fa-fw fa-plus" ]
            []
        ]
    ]

onEnter : Signal.Message -> Attribute
onEnter message =
  on "keydown"
    (Json.customDecoder keyCode is13)
    (always message)

is13 : Int -> Result String ()
is13 code =
  if code == 13
    then Ok()
    else Err "Not the right key code"

timers : Model -> List (Id, Timer) -> Html
timers model timers =
  div
    [ class "timers" ]
    (List.map (timerView model) timers)