aboutsummaryrefslogtreecommitdiff
path: root/src/Update
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-03-22 14:22:50 +0100
committerJoris Guyonvarch2015-03-22 14:22:50 +0100
commit8f9074bf4a4062282f381cf6a4518b191c66cb15 (patch)
tree57f177afccd1a4d00d2052f12039fa103155f2dc /src/Update
parent1ecd777c185cacbf640dc3ab46b84065ef3b40d9 (diff)
Change from button element to div element to prevent space and enter trigger on name and time
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