aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent1ecd777c185cacbf640dc3ab46b84065ef3b40d9 (diff)
Change from button element to div element to prevent space and enter trigger on name and time
Diffstat (limited to 'src')
-rw-r--r--src/Main.elm2
-rw-r--r--src/Update/Update.elm24
-rw-r--r--src/View/Timer.elm8
3 files changed, 21 insertions, 13 deletions
diff --git a/src/Main.elm b/src/Main.elm
index 82c3e20..b84a3ae 100644
--- a/src/Main.elm
+++ b/src/Main.elm
@@ -24,7 +24,7 @@ main : Signal Html
main = Signal.map view model
model : Signal Model
-model = Signal.foldp update (initialModel initialTime) input
+model = Signal.foldp logUpdate (initialModel initialTime) input
input : Signal Action
input =
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
diff --git a/src/View/Timer.elm b/src/View/Timer.elm
index 100514a..c8b6561 100644
--- a/src/View/Timer.elm
+++ b/src/View/Timer.elm
@@ -39,7 +39,7 @@ timerView model (id, timer) =
nameBlockReadOnly : Id -> Timer -> Html
nameBlockReadOnly id timer =
- button
+ div
[ class "name block"
, onClick (Signal.send updates (Edit id Name))
]
@@ -47,7 +47,7 @@ nameBlockReadOnly id timer =
nameBlockEdition : Id -> Timer -> Edition -> Html
nameBlockEdition id timer edition =
- button
+ div
[ [ (True, "name block edition")
, (List.isEmpty edition.chars, "empty")
]
@@ -68,7 +68,7 @@ timerName id = Maybe.withDefault ("Timer " ++ toString id) << .name
timeBlockReadOnly : Id -> Timer -> Html
timeBlockReadOnly id timer =
- button
+ div
[ [ (True, "time block")
, (timer.state == Ringing, "isRinging")
, (timer.state == Running, "isRunning")
@@ -84,7 +84,7 @@ timeBlockReadOnly id timer =
timeBlockEdition : Timer -> Edition -> Html
timeBlockEdition timer edition =
let isEmptyEdition = List.isEmpty edition.chars
- in button
+ in div
[ [ (True, "time block edition")
, (isEmptyEdition, "empty")
]