aboutsummaryrefslogtreecommitdiff
path: root/src/Update
diff options
context:
space:
mode:
Diffstat (limited to 'src/Update')
-rw-r--r--src/Update/Update.elm24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/Update/Update.elm b/src/Update/Update.elm
index 87df965..f3bb263 100644
--- a/src/Update/Update.elm
+++ b/src/Update/Update.elm
@@ -1,6 +1,7 @@
module Update.Update
( Action(..)
, updates
+ , logUpdate
, update
) where
@@ -11,8 +12,8 @@ import Time (Time)
import Maybe
import Keyboard (KeyCode)
import Char
-import Debug
import List
+import Debug
import Model.Model (..)
import Model.Timer (..)
@@ -65,7 +66,7 @@ update action model =
| currentTime <- model.currentTime + delta
, timers <- Dict.map (\id timer -> updateTimer (SubstractTime delta) timer) model.timers
}
- UpdateTimer id action ->
+ UpdateTimer id timerAction ->
let maybeEdition = filterMaybe (\edition -> edition.id == id) model.edition
newModel =
case maybeEdition of
@@ -73,7 +74,7 @@ update action model =
if edition.kind == Time then validEdition model else model
Nothing ->
model
- in { newModel | timers <- Dict.update id (Maybe.map (updateTimer action)) newModel.timers }
+ in { newModel | timers <- Dict.update id (Maybe.map (updateTimer timerAction)) newModel.timers }
RemoveTimer id ->
if numberOfTimers model > 1
then
@@ -93,11 +94,15 @@ update action model =
ClickAway ->
{ model | edition <- Nothing }
KeyPressed keyCode ->
- if isRemoveKeyCode keyCode
+ if isEnterKeyCode keyCode
then
- { model | edition <- Maybe.map (updateEdition DeleteLast) model.edition }
+ validEdition model
else
- { model | edition <- Maybe.map (updateEdition (AddChar keyCode)) model.edition }
+ let editionAction =
+ if isRemoveKeyCode keyCode
+ then DeleteLast
+ else AddChar keyCode
+ in { model | edition <- Maybe.map (updateEdition editionAction) model.edition }
validEdition : Model -> Model
validEdition model =
@@ -107,18 +112,21 @@ validEdition model =
then
model
else
- let action =
+ let timerAction =
case edition.kind of
Name ->
Rename (renderNameEdition edition.chars)
Time ->
SetTime (toTime edition.chars)
in { model
- | timers <- Dict.update edition.id (Maybe.map (updateTimer action)) model.timers
+ | timers <- Dict.update edition.id (Maybe.map (updateTimer timerAction)) model.timers
, edition <- Nothing
}
Nothing ->
model
+isEnterKeyCode : KeyCode -> Bool
+isEnterKeyCode = (==) 13
+
isRemoveKeyCode : KeyCode -> Bool
isRemoveKeyCode = (==) 8