diff options
author | William Carroll <wpcarro@gmail.com> | 2021-01-22T10·49+0000 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2021-01-22T11·00+0000 |
commit | e326b0da45a948668f523d5f715660981a9874c2 (patch) | |
tree | 34c425b23d122aa63b3a15d97b08298ee1db00c7 /assessments/tt/client/src/Main.elm | |
parent | 67e0f93b3bbc386421a276cbd5675f5ac51625ae (diff) | |
parent | ee8e75231cd9d3d4aa3ffbbfa0e3b8511712e1ee (diff) |
Add 'assessments/tt/' from commit 'ee8e75231cd9d3d4aa3ffbbfa0e3b8511712e1ee'
git-subtree-dir: assessments/tt git-subtree-mainline: 67e0f93b3bbc386421a276cbd5675f5ac51625ae git-subtree-split: ee8e75231cd9d3d4aa3ffbbfa0e3b8511712e1ee
Diffstat (limited to 'assessments/tt/client/src/Main.elm')
-rw-r--r-- | assessments/tt/client/src/Main.elm | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/assessments/tt/client/src/Main.elm b/assessments/tt/client/src/Main.elm new file mode 100644 index 000000000000..de71a72db0df --- /dev/null +++ b/assessments/tt/client/src/Main.elm @@ -0,0 +1,62 @@ +module Main exposing (main) + +import Admin +import Browser +import Html exposing (..) +import Login +import Manager +import State +import Url +import User + + +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 -> Browser.Document State.Msg +view 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 + + ( 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.application + { init = State.init + , onUrlChange = State.UrlChanged + , onUrlRequest = State.LinkClicked + , subscriptions = \_ -> Sub.none + , update = State.update + , view = view + } |