diff options
author | William Carroll <wpcarro@gmail.com> | 2020-10-11T15·40+0100 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-10-11T15·40+0100 |
commit | 767fed75c3a6714fe990f4bf906525260e75e68a (patch) | |
tree | 1da375878a5fa9ba2c9d7b5dea2c980bfaf3f0d5 /scratch/habit-screens/client/src/State.elm | |
parent | abf1875934924c4a5146c5b36cfaf9429b974cbe (diff) |
Support multiple HabitTypes
I could have and should have broken this change into smaller pieces, but when I came up for air, I had changed too much, and most of the changes are intermingled. Oh well... this is an exciting change! Include habits for: - Morning - Evening - Payday (the 25th) - First of the Month - First of the Year Since the Morning and Evening routines might be a bit noisy, I'm excluding them from the output using a flag, `include{Morning,Evening}`, which I support in the UI to toggle their visibility. I made *much* more progress on this app that I expected to today, and I *think* -- short of supporting a database and a server -- I'm close to being *completely* finished. Wahoo!
Diffstat (limited to 'scratch/habit-screens/client/src/State.elm')
-rw-r--r-- | scratch/habit-screens/client/src/State.elm | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/scratch/habit-screens/client/src/State.elm b/scratch/habit-screens/client/src/State.elm index 5fde06c8000c..c75c99322249 100644 --- a/scratch/habit-screens/client/src/State.elm +++ b/scratch/habit-screens/client/src/State.elm @@ -1,21 +1,31 @@ module State exposing (..) -import Date +import Date exposing (Date) import Set exposing (Set) import Task import Time exposing (Weekday(..)) +type alias WeekdayLabel = + String + + +type alias HabitLabel = + String + + type Msg = DoNothing | SetView View - | ReceiveDate Date.Date - | ToggleHabit Int + | ReceiveDate Date + | ToggleHabit WeekdayLabel HabitLabel | MaybeAdjustWeekday | ViewToday | ViewPrevious | ViewNext | ClearAll + | ToggleMorning + | ToggleEvening type View @@ -32,18 +42,24 @@ type HabitType type alias Habit = - { label : String + { label : HabitLabel , habitType : HabitType , minutesDuration : Int } +type alias CompletedHabits = + Set ( WeekdayLabel, HabitLabel ) + + type alias Model = { isLoading : Bool , view : View - , today : Maybe Weekday - , completed : Set Int + , today : Maybe Date + , completed : CompletedHabits , visibleDayOfWeek : Maybe Weekday + , includeMorning : Bool + , includeEvening : Bool } @@ -106,6 +122,8 @@ init = , today = Nothing , completed = Set.empty , visibleDayOfWeek = Nothing + , includeMorning = False + , includeEvening = False } , Date.today |> Task.perform ReceiveDate ) @@ -129,20 +147,20 @@ update msg ({ today, visibleDayOfWeek, completed } as model) = ReceiveDate x -> ( { model - | today = Just (Date.weekday x) + | today = Just x , visibleDayOfWeek = Just (Date.weekday x) } , Cmd.none ) - ToggleHabit i -> + ToggleHabit weekdayLabel habitLabel -> ( { model | completed = - if Set.member i completed then - Set.remove i completed + if Set.member ( weekdayLabel, habitLabel ) completed then + Set.remove ( weekdayLabel, habitLabel ) completed else - Set.insert i completed + Set.insert ( weekdayLabel, habitLabel ) completed } , Cmd.none ) @@ -151,7 +169,7 @@ update msg ({ today, visibleDayOfWeek, completed } as model) = ( model, Date.today |> Task.perform ReceiveDate ) ViewToday -> - ( { model | visibleDayOfWeek = today }, Cmd.none ) + ( { model | visibleDayOfWeek = today |> Maybe.map Date.weekday }, Cmd.none ) ViewPrevious -> ( { model @@ -169,3 +187,9 @@ update msg ({ today, visibleDayOfWeek, completed } as model) = ClearAll -> ( { model | completed = Set.empty }, Cmd.none ) + + ToggleMorning -> + ( { model | includeMorning = not model.includeMorning }, Cmd.none ) + + ToggleEvening -> + ( { model | includeEvening = not model.includeEvening }, Cmd.none ) |