aboutsummaryrefslogtreecommitdiff
path: root/src/View/Timer.elm
blob: 13f071ce9cdc339397f07fba6476f692bc38dfad (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
module View.Timer
  ( timerView
  ) where

import Html (..)
import Html.Attributes (..)
import Html.Events (..)
import String
import Time (Time)
import Signal

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

import Update.Update (..)
import Update.UpdateTimer (..)

timerView : (Id, Timer) -> Html
timerView (id, timer) =
  div
    [ class <| "timer" ++ (if timer.isRunning then " isRunning" else "") ]
    [ button
        [ class "name block"
        , onClick (Signal.send updates (UpdateTimer id ToggleRunning))
        ]
        [ text timer.name ]
    , div
        [ class <| "time block" ]
        [ text (timeView timer.time) ]
    , button
        [ class <| "remove block"
        , onClick (Signal.send updates (RemoveTimer id))
        ]
        [ i [ class "fa fa-fw fa-remove" ] [] ]
    ]

timeView : Time -> String
timeView time =
  let totalSeconds = truncate (time / 1000)
      totalMinutes = totalSeconds // 60
      restSeconds = totalSeconds `rem` 60
  in  (toString totalMinutes) ++ ":" ++ (String.padLeft 2 '0' (toString restSeconds))