From 79cf42abd529e2b4db5577f835a206e400e20e24 Mon Sep 17 00:00:00 2001 From: William Carroll Date: Sun, 11 Oct 2020 15:17:20 +0100 Subject: [PATCH] Render time remaining in UI Show the number of minutes remaining before completing all of the tasks. --- scratch/habit-screens/client/src/Habits.elm | 40 +++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/scratch/habit-screens/client/src/Habits.elm b/scratch/habit-screens/client/src/Habits.elm index 63cb0918a..92f1455da 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