diff options
author | William Carroll <wpcarro@gmail.com> | 2020-10-11T14·17+0100 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-10-11T14·17+0100 |
commit | 79cf42abd529e2b4db5577f835a206e400e20e24 (patch) | |
tree | b312b586af29f9cbdc3947680380fbbef1e552b6 /scratch | |
parent | 5684608fedaf7d5cf0bebdb9494b5f6565e42e9c (diff) |
Render time remaining in UI
Show the number of minutes remaining before completing all of the tasks.
Diffstat (limited to 'scratch')
-rw-r--r-- | scratch/habit-screens/client/src/Habits.elm | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/scratch/habit-screens/client/src/Habits.elm b/scratch/habit-screens/client/src/Habits.elm index 63cb0918abd1..92f1455dac38 100644 --- a/scratch/habit-screens/client/src/Habits.elm +++ b/scratch/habit-screens/client/src/Habits.elm @@ -4,7 +4,7 @@ import Browser import Html exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (..) -import Set +import Set exposing (Set) import State import Time exposing (Weekday(..)) import UI @@ -205,6 +205,20 @@ habitsFor weekday = toHabit sunday +timeRemaining : Set Int -> List State.Habit -> Int +timeRemaining completed habits = + habits + |> List.indexedMap + (\i { minutesDuration } -> + if Set.member i completed then + 0 + + else + minutesDuration + ) + |> List.sum + + render : State.Model -> Html State.Msg render { today, visibleDayOfWeek, completed } = case visibleDayOfWeek of @@ -247,7 +261,29 @@ render { today, visibleDayOfWeek, completed } = [ text "next ›" ] ] ] - , ul [ class "pt-6" ] + , if today == visibleDayOfWeek then + p [ class "text-center" ] + [ let + t = + timeRemaining completed (habitsFor weekday) + in + if t == 0 then + text "Nothing to do!" + + else + text + ((weekday + |> habitsFor + |> timeRemaining completed + |> String.fromInt + ) + ++ " minutes remaining" + ) + ] + + else + text "" + , ul [] (weekday |> habitsFor |> List.indexedMap |