Support Msg to clear all completed tasks
Add a simple button to clear all completed tasks.
This commit is contained in:
parent
79cf42abd5
commit
abf1875934
2 changed files with 45 additions and 5 deletions
|
@ -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." ]
|
p [] [ text "Unable to display habits because we do not know what day of the week it is." ]
|
||||||
|
|
||||||
Just weekday ->
|
Just weekday ->
|
||||||
|
let
|
||||||
|
habits =
|
||||||
|
habitsFor weekday
|
||||||
|
in
|
||||||
div
|
div
|
||||||
[ Utils.class
|
[ Utils.class
|
||||||
[ Always "container mx-auto py-6 px-6"
|
[ Always "container mx-auto py-6 px-6"
|
||||||
|
@ -265,15 +269,14 @@ render { today, visibleDayOfWeek, completed } =
|
||||||
p [ class "text-center" ]
|
p [ class "text-center" ]
|
||||||
[ let
|
[ let
|
||||||
t =
|
t =
|
||||||
timeRemaining completed (habitsFor weekday)
|
timeRemaining completed habits
|
||||||
in
|
in
|
||||||
if t == 0 then
|
if t == 0 then
|
||||||
text "Nothing to do!"
|
text "Nothing to do!"
|
||||||
|
|
||||||
else
|
else
|
||||||
text
|
text
|
||||||
((weekday
|
((habits
|
||||||
|> habitsFor
|
|
||||||
|> timeRemaining completed
|
|> timeRemaining completed
|
||||||
|> String.fromInt
|
|> 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
|
else
|
||||||
text ""
|
text ""
|
||||||
, ul []
|
, ul []
|
||||||
(weekday
|
(habits
|
||||||
|> habitsFor
|
|
||||||
|> List.indexedMap
|
|> List.indexedMap
|
||||||
(\i { label, minutesDuration } ->
|
(\i { label, minutesDuration } ->
|
||||||
let
|
let
|
||||||
|
|
|
@ -15,6 +15,7 @@ type Msg
|
||||||
| ViewToday
|
| ViewToday
|
||||||
| ViewPrevious
|
| ViewPrevious
|
||||||
| ViewNext
|
| ViewNext
|
||||||
|
| ClearAll
|
||||||
|
|
||||||
|
|
||||||
type View
|
type View
|
||||||
|
@ -165,3 +166,6 @@ update msg ({ today, visibleDayOfWeek, completed } as model) =
|
||||||
}
|
}
|
||||||
, Cmd.none
|
, Cmd.none
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ClearAll ->
|
||||||
|
( { model | completed = Set.empty }, Cmd.none )
|
||||||
|
|
Loading…
Reference in a new issue