From af9465f928f28344aa59a407adb21e5ac047a0f9 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Thu, 19 Mar 2015 00:55:50 +0100 Subject: Adding a Ringing state that animate the color, does not ring a sound for the moment --- src/Update/Update.elm | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'src/Update/Update.elm') diff --git a/src/Update/Update.elm b/src/Update/Update.elm index 8285760..3bdcc2b 100644 --- a/src/Update/Update.elm +++ b/src/Update/Update.elm @@ -6,6 +6,7 @@ module Update.Update import Signal import Dict +import Dict (Dict) import Time (Time) import Maybe import Keyboard (KeyCode) @@ -20,8 +21,11 @@ import Model.IdGenerator (..) import Update.UpdateTimer (..) import Update.UpdateTimerEdition (..) +import Utils.Maybe (..) + type Action = NoOp + | Initialize | AddNewTimer | DeltaTime Time | UpdateTimer Id TimerAction @@ -38,6 +42,8 @@ update : Action -> Model -> Model update action model = case action of NoOp -> model + Initialize -> + initialModel model.currentTime AddNewTimer -> let (id, newTimerIdGenerator) = getId model.timerIdGenerator timerName = "Timer " ++ (toString id) @@ -51,14 +57,17 @@ update action model = , timers <- substractTimersTime delta model.timers } UpdateTimer id action -> - let inEdition = - model.timerEdition - |> Maybe.map (\timerEdition -> timerEdition.id == id) - |> Maybe.withDefault False - in if inEdition - then - model - else + + let maybeTimerEdition = filterMaybe (\timerEdition -> timerEdition.id == id) model.timerEdition + in case model.timerEdition of + Just timerEdition -> + { model + | timers <- + updateTimerTime timerEdition model.timers + |> Dict.update id (Maybe.map (updateTimer action)) + , timerEdition <- Nothing + } + Nothing -> { model | timers <- Dict.update id (Maybe.map (updateTimer action)) model.timers } RemoveTimer id -> { model | timers <- Dict.remove id model.timers } @@ -71,7 +80,7 @@ update action model = case model.timerEdition of Just timerEdition -> { model - | timers <- Dict.update timerEdition.id (Maybe.map (updateTimer (SetTime (toTime timerEdition.numbers)))) model.timers + | timers <- updateTimerTime timerEdition model.timers , timerEdition <- Nothing } Nothing -> @@ -81,5 +90,6 @@ update action model = KeyPressed keyCode -> { model | timerEdition <- Maybe.map (updateTimerEdition (keyCodeToChar keyCode)) model.timerEdition } -isEnter : KeyCode -> Bool -isEnter = (==) 107 +updateTimerTime : TimerEdition -> Dict Id Timer -> Dict Id Timer +updateTimerTime timerEdition = + Dict.update timerEdition.id (Maybe.map (updateTimer (SetTime (toTime timerEdition.numbers)))) -- cgit v1.2.3