about summary refs log tree commit diff
path: root/scratch/habit-screens/client/src/State.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/State.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/State.elm')
-rw-r--r--scratch/habit-screens/client/src/State.elm80
1 files changed, 80 insertions, 0 deletions
diff --git a/scratch/habit-screens/client/src/State.elm b/scratch/habit-screens/client/src/State.elm
new file mode 100644
index 000000000000..9e594f9a2462
--- /dev/null
+++ b/scratch/habit-screens/client/src/State.elm
@@ -0,0 +1,80 @@
+module State exposing (..)
+
+import Date
+import Set exposing (Set)
+import Task
+import Time exposing (Weekday(..))
+
+
+type Msg
+    = DoNothing
+    | SetView View
+    | ReceiveDate Date.Date
+    | ToggleHabit Int
+
+
+type View
+    = Habits
+
+
+type HabitType
+    = Daily
+    | Weekly
+    | Yearly
+
+
+type alias Habit =
+    String
+
+
+type alias Model =
+    { isLoading : Bool
+    , view : View
+    , dayOfWeek : Maybe Weekday
+    , completed : Set Int
+    }
+
+
+{-| The initial state for the application.
+-}
+init : ( Model, Cmd Msg )
+init =
+    ( { isLoading = False
+      , view = Habits
+      , dayOfWeek = Nothing
+      , completed = Set.empty
+      }
+    , Date.today |> Task.perform ReceiveDate
+    )
+
+
+{-| Now that we have state, we need a function to change the state.
+-}
+update : Msg -> Model -> ( Model, Cmd Msg )
+update msg ({ completed } as model) =
+    case msg of
+        DoNothing ->
+            ( model, Cmd.none )
+
+        SetView x ->
+            ( { model
+                | view = x
+                , isLoading = True
+              }
+            , Cmd.none
+            )
+
+        ReceiveDate x ->
+            ( { model | dayOfWeek = Just Sun }, Cmd.none )
+
+        ToggleHabit i ->
+            ( { model
+                | completed =
+                    if Set.member i completed then
+                        Set.remove i completed
+
+                    else
+                        Set.insert i completed
+              }
+            , Cmd.none
+            )