From 8f9074bf4a4062282f381cf6a4518b191c66cb15 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sun, 22 Mar 2015 14:22:50 +0100 Subject: Change from button element to div element to prevent space and enter trigger on name and time --- src/Update/Update.elm | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/Update') 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 -- cgit v1.2.3