about summary refs log tree commit diff
path: root/client/src/Main.elm
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-07-31T17·32+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-07-31T17·57+0100
commit421c71c8922731563771ed75be7f28c9a559c068 (patch)
treef7723ade399bb02a638fa3df9371cdb072262eb5 /client/src/Main.elm
parent29a00dc571b53b08064915c34e0d951467b6f1e4 (diff)
Support a basic client-side login flow
I will need to remove some of the baggage like:

- Scrub any copy about restaurants
- delete Restaurant.elm
- Change Owner.elm -> Manager.elm
Diffstat (limited to 'client/src/Main.elm')
-rw-r--r--client/src/Main.elm57
1 files changed, 44 insertions, 13 deletions
diff --git a/client/src/Main.elm b/client/src/Main.elm
index 30006460cde9..de71a72db0df 100644
--- a/client/src/Main.elm
+++ b/client/src/Main.elm
@@ -1,31 +1,62 @@
 module Main exposing (main)
 
+import Admin
 import Browser
 import Html exposing (..)
-import Landing
 import Login
+import Manager
 import State
+import Url
+import User
 
 
-subscriptions : State.Model -> Sub State.Msg
-subscriptions model =
-    Sub.none
+viewForRoute : State.Route -> (State.Model -> Html State.Msg)
+viewForRoute route =
+    case route of
+        State.Login ->
+            Login.render
+
+        State.UserHome ->
+            User.render
+
+        State.ManagerHome ->
+            Manager.render
+
+        State.AdminHome ->
+            Admin.render
 
 
-view : State.Model -> Html State.Msg
+view : State.Model -> Browser.Document State.Msg
 view model =
-    case model.view of
-        State.Landing ->
-            Landing.render model
+    { title = "TripPlanner"
+    , body =
+        [ case ( model.session, model.route ) of
+            -- Redirect to /login when someone is not authenticated.
+            -- TODO(wpcarro): We should ensure that /login shows in the URL
+            -- bar.
+            ( Nothing, _ ) ->
+                Login.render model
 
-        State.Login ->
-            Login.render model
+            ( Just session, Nothing ) ->
+                Login.render model
+
+            -- Authenticated
+            ( Just session, Just route ) ->
+                if State.isAuthorized session.role route then
+                    viewForRoute route model
+
+                else
+                    text "Access denied. You are not authorized to be here. Evacuate the area immediately"
+        ]
+    }
 
 
 main =
-    Browser.element
-        { init = \() -> ( State.init, Cmd.none )
-        , subscriptions = subscriptions
+    Browser.application
+        { init = State.init
+        , onUrlChange = State.UrlChanged
+        , onUrlRequest = State.LinkClicked
+        , subscriptions = \_ -> Sub.none
         , update = State.update
         , view = view
         }