onasty/web/src/Layouts/Header.elm(view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
module Layouts.Header exposing (Model, Msg, Props, layout)
import Auth.User
import Effect exposing (Effect)
import Html exposing (Html)
import Html.Attributes as Attr
import Html.Events
import Layout exposing (Layout)
import Route exposing (Route)
import Route.Path
import Shared
import View exposing (View)
type alias Props =
{}
layout : Props -> Shared.Model -> Route () -> Layout () Model Msg contentMsg
layout _ shared _ =
Layout.new
{ init = init
, update = update
, view = view shared
, subscriptions = subscriptions
}
-- MODEL
type alias Model =
{}
init : () -> ( Model, Effect Msg )
init _ =
( {}, Effect.none )
-- UPDATE
type Msg
= UserClickedLogout
update : Msg -> Model -> ( Model, Effect Msg )
update msg model =
case msg of
UserClickedLogout ->
( model, Effect.logout )
subscriptions : Model -> Sub Msg
subscriptions _ =
Sub.none
-- VIEW
view : Shared.Model -> { toContentMsg : Msg -> contentMsg, content : View contentMsg, model : Model } -> View contentMsg
view shared { toContentMsg, content } =
{ title = content.title
, body =
[ viewNavbar shared |> Html.map toContentMsg
, Html.main_ [] content.body
]
}
viewNavbar : Shared.Model -> Html Msg
viewNavbar shared =
Html.header [ Attr.class "navbar" ]
[ Html.nav [ Attr.class "f-row justify-content:space-between" ]
[ Html.ul [ Attr.attribute "role" "list" ]
[ Html.li [] [ viewNavLink ( "home", Route.Path.Home_ ) ] ]
, Html.ul [ Attr.attribute "role" "list" ]
(case shared.user of
Auth.User.SignedIn _ ->
[ Html.li [] [ viewNavLink ( "profile", Route.Path.Profile_Me ) ]
, Html.li [] [ Html.a [ Html.Events.onClick UserClickedLogout ] [ Html.text "logout" ] ]
]
Auth.User.NotSignedIn ->
viewNotSignedInNav
Auth.User.RefreshingTokens ->
viewNotSignedInNav
)
]
]
viewNotSignedInNav : List (Html msg)
viewNotSignedInNav =
[ Html.li [] [ viewNavLink ( "sign in", Route.Path.Auth ) ]
]
viewNavLink : ( String, Route.Path.Path ) -> Html msg
viewNavLink ( label, path ) =
Html.a
[ Route.Path.href path ]
[ Html.text label ]
|