aboutsummaryrefslogtreecommitdiff
path: root/src/Update/UpdateTimerEdition.elm
blob: e9493eb21c1310c8cd5358d77897ce2af2d47560 (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
module Update.UpdateTimerEdition
  ( updateTimerEdition
  , TimerEditionAction(..)
  ) where

import Char (..)

import Model.TimerEdition (..)

import Utils.List (..)

type TimerEditionAction =
  DeleteLast
  | AddNumber KeyCode

updateTimerEdition : TimerEditionAction -> TimerEdition -> TimerEdition
updateTimerEdition action timerEdition =
  case action of
    DeleteLast ->
      case maybeTail timerEdition.numbers of
        Just tailNumbers ->
          { timerEdition | numbers <- tailNumbers }
        Nothing ->
          timerEdition
    AddNumber keyCode ->
      case keyCodeToNumberChar keyCode of
        Just char ->
          if isDigit char
            then
              { timerEdition | numbers <- char :: timerEdition.numbers }
            else
              timerEdition
        Nothing ->
          timerEdition