From a2b550b87a5f5bafa0d004606267838b135bcdb9 Mon Sep 17 00:00:00 2001 From: Joris Guyonvarch Date: Sun, 22 Mar 2015 13:44:03 +0100 Subject: Validating time edition before updating timer with any action --- src/Update/Update.elm | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Update/Update.elm b/src/Update/Update.elm index 5a4b12a..8fd5cb3 100644 --- a/src/Update/Update.elm +++ b/src/Update/Update.elm @@ -67,14 +67,13 @@ update action model = } UpdateTimer id action -> let maybeEdition = filterMaybe (\edition -> edition.id == id) model.edition - in case maybeEdition of - Just edition -> - { model - | timers <- Dict.update id (Maybe.map (updateTimer action)) model.timers - , edition <- Nothing - } - Nothing -> - { model | timers <- Dict.update id (Maybe.map (updateTimer action)) model.timers } + newModel = + case maybeEdition of + Just edition -> + if edition.kind == Time then validEdition model else model + Nothing -> + model + in { newModel | timers <- Dict.update id (Maybe.map (updateTimer action)) newModel.timers } RemoveTimer id -> if numberOfTimers model > 1 then -- cgit v1.2.3