From 2613aeeae0f4de44842ff0e796603d0316a61a14 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Wed, 18 Mar 2015 00:32:17 +0100 Subject: Can edit the time, unfortunately the enter key is overriden so the '+' key of the numpad is used instead --- src/Update/Update.elm | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'src/Update/Update.elm') 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 -- cgit v1.2.3