aboutsummaryrefslogtreecommitdiff
path: root/src/Update/Update.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/Update/Update.elm')
-rw-r--r--src/Update/Update.elm35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/Update/Update.elm b/src/Update/Update.elm
index fa11921..4725970 100644
--- a/src/Update/Update.elm
+++ b/src/Update/Update.elm
@@ -8,6 +8,8 @@ import Signal
import Dict
import Time (Time)
import Maybe
+import Keyboard (KeyCode)
+import Char
import Model.Model (..)
import Model.Timer (..)
@@ -16,6 +18,7 @@ import Model.Id (..)
import Model.IdGenerator (..)
import Update.UpdateTimer (..)
+import Update.UpdateTimerEdition (..)
type Action =
NoOp
@@ -25,6 +28,7 @@ type Action =
| RemoveTimer Id
| EditTimer Id
| ReadOnly
+ | KeyPressed KeyCode
updates : Signal.Channel Action
updates = Signal.channel NoOp
@@ -46,10 +50,37 @@ update action model =
, timers <- substractTimersTime delta model.timers
}
UpdateTimer id action ->
- { model | timers <- Dict.update id (Maybe.map (updateTimer action)) model.timers }
+ let inEdition =
+ model.timerEdition
+ |> Maybe.map (\timerEdition -> timerEdition.id == id)
+ |> Maybe.withDefault False
+ in if inEdition
+ then
+ model
+ else
+ { model | timers <- Dict.update id (Maybe.map (updateTimer action)) model.timers }
RemoveTimer id ->
{ model | timers <- Dict.remove id model.timers }
EditTimer id ->
- { model | timerEdition <- Just (newTimerEdition id) }
+ { model
+ | timerEdition <- Just (newTimerEdition id)
+ , timers <- Dict.update id (Maybe.map (updateTimer Pause)) model.timers
+ }
ReadOnly ->
{ model | timerEdition <- Nothing }
+ KeyPressed keyCode ->
+ if isEnter keyCode
+ then
+ case model.timerEdition of
+ Just timerEdition ->
+ { model
+ | timers <- Dict.update timerEdition.id (Maybe.map (updateTimer (SetTime (toTime timerEdition.numbers)))) model.timers
+ , timerEdition <- Nothing
+ }
+ Nothing ->
+ { model | timerEdition <- Nothing }
+ else
+ { model | timerEdition <- Maybe.map (updateTimerEdition (keyCodeToChar keyCode)) model.timerEdition }
+
+isEnter : KeyCode -> Bool
+isEnter = (==) 107