diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Model/Model.elm | 5 | ||||
-rw-r--r-- | src/Update/Update.elm | 6 | ||||
-rw-r--r-- | src/View/Timer.elm | 20 |
3 files changed, 22 insertions, 9 deletions
diff --git a/src/Model/Model.elm b/src/Model/Model.elm index b7ac48a..ad1e9da 100644 --- a/src/Model/Model.elm +++ b/src/Model/Model.elm @@ -2,11 +2,13 @@ module Model.Model ( Model , initialModel , substractTimersTime + , numberOfTimers ) where import Dict (Dict) import Dict import Time (Time) +import List import Model.Timer (..) import Model.TimerEdition (..) @@ -33,3 +35,6 @@ initialModel initialTime = substractTimersTime : Time -> Dict Id Timer -> Dict Id Timer substractTimersTime t timers = Dict.map (\id timer -> substractTimerTime t timer) timers + +numberOfTimers : Model -> Int +numberOfTimers = List.length << Dict.toList << .timers diff --git a/src/Update/Update.elm b/src/Update/Update.elm index c6c5f32..2cb45cb 100644 --- a/src/Update/Update.elm +++ b/src/Update/Update.elm @@ -76,7 +76,11 @@ update action model = Nothing -> { model | timers <- Dict.update id (Maybe.map (updateTimer action)) model.timers } RemoveTimer id -> - { model | timers <- Dict.remove id model.timers } + if numberOfTimers model > 1 + then + { model | timers <- Dict.remove id model.timers } + else + model EditTimer id -> { model | timerEdition <- Just (newTimerEdition id) diff --git a/src/View/Timer.elm b/src/View/Timer.elm index 2325d3a..9c302a4 100644 --- a/src/View/Timer.elm +++ b/src/View/Timer.elm @@ -37,7 +37,7 @@ timerView model (id, timer) = , restartBlock (id, timer) , playPauseBlock (id, timer) , stopBlock (id, timer) - , removeBlock (id, timer) + , removeBlock model (id, timer) ] nameBlock : (Id, Timer) -> Html @@ -105,13 +105,17 @@ stopBlock (id, timer) = ] [ i [ class "fa fa-fw fa-stop" ] [] ] -removeBlock : (Id, Timer) -> Html -removeBlock (id, timer) = - button - [ class <| "remove block" - , onClick (Signal.send updates (RemoveTimer id)) - ] - [ i [ class "fa fa-fw fa-remove" ] [] ] +removeBlock : Model -> (Id, Timer) -> Html +removeBlock model (id, timer) = + let removeClass = + if numberOfTimers model > 1 + then "remove" + else "singleRemove" + in button + [ class <| "block " ++ removeClass + , onClick (Signal.send updates (RemoveTimer id)) + ] + [ i [ class "fa fa-fw fa-remove" ] [] ] stopIfRinging : (Id, Timer) -> Signal.Message -> Signal.Message stopIfRinging (id, timer) message = |