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.elm32
1 files changed, 21 insertions, 11 deletions
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))))