Support Msg to clear all completed tasks

Add a simple button to clear all completed tasks.
This commit is contained in:
William Carroll 2020-10-11 15:39:01 +01:00
parent 79cf42abd5
commit abf1875934
2 changed files with 45 additions and 5 deletions

View file

@ -226,6 +226,10 @@ render { today, visibleDayOfWeek, completed } =
p [] [ text "Unable to display habits because we do not know what day of the week it is." ]
Just weekday ->
let
habits =
habitsFor weekday
in
div
[ Utils.class
[ Always "container mx-auto py-6 px-6"
@ -265,15 +269,14 @@ render { today, visibleDayOfWeek, completed } =
p [ class "text-center" ]
[ let
t =
timeRemaining completed (habitsFor weekday)
timeRemaining completed habits
in
if t == 0 then
text "Nothing to do!"
else
text
((weekday
|> habitsFor
((habits
|> timeRemaining completed
|> String.fromInt
)
@ -281,11 +284,44 @@ render { today, visibleDayOfWeek, completed } =
)
]
else
text ""
, if today == visibleDayOfWeek then
div []
[ UI.button
[ onClick
(if Set.size completed == 0 then
State.DoNothing
else
State.ClearAll
)
, Utils.class
[ Always "ml-10"
, If (Set.size completed == 0)
"text-gray-500 cursor-not-allowed"
"text-red-500 underline cursor-pointer"
]
]
[ let
numCompleted =
habits
|> List.indexedMap (\i _ -> i)
|> List.filter (\i -> Set.member i completed)
|> List.length
in
if numCompleted == 0 then
text "Clear"
else
text ("Clear (" ++ String.fromInt numCompleted ++ ")")
]
]
else
text ""
, ul []
(weekday
|> habitsFor
(habits
|> List.indexedMap
(\i { label, minutesDuration } ->
let

View file

@ -15,6 +15,7 @@ type Msg
| ViewToday
| ViewPrevious
| ViewNext
| ClearAll
type View
@ -165,3 +166,6 @@ update msg ({ today, visibleDayOfWeek, completed } as model) =
}
, Cmd.none
)
ClearAll ->
( { model | completed = Set.empty }, Cmd.none )