about summary refs log tree commit diff
path: root/client/src/State.elm
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-08-02T09·51+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-08-02T09·51+0100
commit57b6472e2fbd963cc18237d596eb61bb767a1206 (patch)
tree7df0dee0ed7f1f3f1dda97354208ad1dd31e129e /client/src/State.elm
parentac9629cad027b2797c016a2a5367d4ad4c04962c (diff)
Define defaults for init in State.elm
Problem: When I'm working on a feature, I save my code, and elm-live reloads the
browser. This is usually good, except that the application state is
reinitialized, which usually means that the view changes.

I defined two state configurations, and I expect to define more:
- prod: The initial state for the application
- userHome: The state I'd like to use when developing a feature for the UserHome
  page.

Idea: For more ad-hoc configurations, I can store the application state in
LocalStorage and restore it in between page refreshes.
Diffstat (limited to 'client/src/State.elm')
-rw-r--r--client/src/State.elm42
1 files changed, 39 insertions, 3 deletions
diff --git a/client/src/State.elm b/client/src/State.elm
index 66b3e57f0c79..190cab7eacae 100644
--- a/client/src/State.elm
+++ b/client/src/State.elm
@@ -379,10 +379,10 @@ routeParser =
         ]
 
 
-{-| The initial state for the application.
+{-| Set init to `prod` when going live.
 -}
-init : () -> Url.Url -> Nav.Key -> ( Model, Cmd Msg )
-init _ url key =
+prod : () -> Url.Url -> Nav.Key -> ( Model, Cmd Msg )
+prod _ url key =
     let
         ( startDatePicker, startDatePickerCmd ) =
             DatePicker.init
@@ -421,6 +421,42 @@ init _ url key =
     )
 
 
+{-| When working on a feature for the UserHome, use this.
+-}
+userHome : () -> Url.Url -> Nav.Key -> ( Model, Cmd Msg )
+userHome flags url key =
+    let
+        ( model, cmd ) =
+            prod flags url key
+    in
+    ( { model
+        | route = Just UserHome
+        , session = Just { username = "mimi", role = User }
+        , trips =
+            RemoteData.Success
+                [ { destination = "Barcelona"
+                  , startDate = Date.fromCalendarDate 2020 Time.Sep 25
+                  , endDate = Date.fromCalendarDate 2020 Time.Oct 5
+                  , comment = "Blah"
+                  }
+                , { destination = "Paris"
+                  , startDate = Date.fromCalendarDate 2021 Time.Jan 1
+                  , endDate = Date.fromCalendarDate 2021 Time.Feb 1
+                  , comment = "Bon voyage!"
+                  }
+                ]
+      }
+    , cmd
+    )
+
+
+{-| The initial state for the application.
+-}
+init : () -> Url.Url -> Nav.Key -> ( Model, Cmd Msg )
+init flags url key =
+    prod flags url key
+
+
 {-| Now that we have state, we need a function to change the state.
 -}
 update : Msg -> Model -> ( Model, Cmd Msg )