about summary refs log tree commit diff
path: root/scratch/habit-screens/client/src/Habits.elm
blob: e6fd606f5dbe1b1ed4d9f682259fb6f01d746812 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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 ]
                                    ]
                            )
                    )
                ]