about summary refs log tree commit diff
path: root/scratch/habit-screens/client/src/Habits.elm
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-10-10T16·04+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-10-10T16·04+0100
commit9d331f307747d062ea9de07f553864cff9ed918a (patch)
tree7a14b57aff15c8f6c13b3a9745d4b17385ed494b /scratch/habit-screens/client/src/Habits.elm
parent02ce74eada9df71f760bef4dc0eccddab8d6fbfe (diff)
Begin working on Habit Screens project
Created a small MVP for digitizing my weekly habits. Much more to come.

Lots of things happening:

- Copied the boilerplate to get started
- Added a brief project-level README
- Outlined my ambitions in design.md

See README and design.md for more context on this project.
Diffstat (limited to 'scratch/habit-screens/client/src/Habits.elm')
-rw-r--r--scratch/habit-screens/client/src/Habits.elm169
1 files changed, 169 insertions, 0 deletions
diff --git a/scratch/habit-screens/client/src/Habits.elm b/scratch/habit-screens/client/src/Habits.elm
new file mode 100644
index 000000000000..e6fd606f5dbe
--- /dev/null
+++ b/scratch/habit-screens/client/src/Habits.elm
@@ -0,0 +1,169 @@
+module Habits exposing (render)
+
+import Browser
+import Html exposing (..)
+import Html.Attributes exposing (..)
+import Html.Events exposing (..)
+import Set
+import State
+import Time exposing (Weekday(..))
+
+
+morning : List State.Habit
+morning =
+    [ "Make bed"
+    , "Brush teeth"
+    , "Shower"
+    , "Do push-ups"
+    , "Meditate"
+    ]
+
+
+evening : List State.Habit
+evening =
+    [ "Read (30 minutes)"
+    , "Record in State.Habit Journal"
+    ]
+
+
+monday : List State.Habit
+monday =
+    [ "Bikram Yoga @ 17:00 (90 min)"
+    ]
+
+
+tuesday : List State.Habit
+tuesday =
+    [ "Bikram Yoga @ 18:00 (90 min)"
+    ]
+
+
+wednesday : List State.Habit
+wednesday =
+    [ "Shave"
+    , "Bikram Yoga @ 17:00 (90 min)"
+    ]
+
+
+thursday : List State.Habit
+thursday =
+    []
+
+
+friday : List State.Habit
+friday =
+    [ "Bikram Yoga @ 17:00 (60 min)"
+    , "Take-out trash"
+    , "Shop for groceries"
+    ]
+
+
+saturday : List State.Habit
+saturday =
+    [ "Nap"
+    ]
+
+
+sunday : List State.Habit
+sunday =
+    [ "Shampoo"
+    , "Shave"
+    , "Trim nails"
+    , "Combine trash cans"
+    , "Mop tile and wood floors"
+    , "Laundry"
+    , "Vacuum bedroom"
+    , "Dust surfaces"
+    , "Clean mirrors"
+    , "Clean desk"
+    ]
+
+
+weekdayName : Weekday -> String
+weekdayName weekday =
+    case weekday of
+        Mon ->
+            "Monday"
+
+        Tue ->
+            "Tuesday"
+
+        Wed ->
+            "Wednesday"
+
+        Thu ->
+            "Thursday"
+
+        Fri ->
+            "Friday"
+
+        Sat ->
+            "Saturday"
+
+        Sun ->
+            "Sunday"
+
+
+habitsFor : Weekday -> List State.Habit
+habitsFor weekday =
+    case weekday of
+        Mon ->
+            monday
+
+        Tue ->
+            tuesday
+
+        Wed ->
+            wednesday
+
+        Thu ->
+            thursday
+
+        Fri ->
+            friday
+
+        Sat ->
+            saturday
+
+        Sun ->
+            sunday
+
+
+tailwind : List ( String, Bool ) -> Attribute msg
+tailwind classes =
+    classes
+        |> List.filter (\( k, v ) -> v)
+        |> List.map (\( k, v ) -> k)
+        |> String.join " "
+        |> class
+
+
+render : State.Model -> Html State.Msg
+render { dayOfWeek, completed } =
+    case dayOfWeek of
+        Nothing ->
+            p [] [ text "Unable to display habits because we do not know what day of the week it is." ]
+
+        Just weekday ->
+            div [ class "font-mono py-6 px-6" ]
+                [ h1 [ class "text-2xl text-center" ] [ text (weekdayName weekday) ]
+                , ul []
+                    (weekday
+                        |> habitsFor
+                        |> List.indexedMap
+                            (\i x ->
+                                li [ class "text-xl" ]
+                                    [ button
+                                        [ class "py-5 px-6"
+                                        , tailwind
+                                            [ ( "line-through"
+                                              , Set.member i completed
+                                              )
+                                            ]
+                                        , onClick (State.ToggleHabit i)
+                                        ]
+                                        [ text x ]
+                                    ]
+                            )
+                    )
+                ]