about summary refs log tree commit diff
path: root/scratch/habit-screens/client/src/State.elm
diff options
context:
space:
mode:
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
+            )