Bring back menu items for logging in and out
This commit is contained in:
parent
ea47fb8b50
commit
1c4212f5d0
2 changed files with 16 additions and 16 deletions
|
@ -36,13 +36,8 @@ data App = App
|
||||||
data MenuItem = MenuItem
|
data MenuItem = MenuItem
|
||||||
{ menuItemLabel :: Text
|
{ menuItemLabel :: Text
|
||||||
, menuItemRoute :: Route App
|
, menuItemRoute :: Route App
|
||||||
, menuItemAccessCallback :: Bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data MenuTypes
|
|
||||||
= NavbarLeft MenuItem
|
|
||||||
| NavbarRight MenuItem
|
|
||||||
|
|
||||||
-- This is where we define all of the routes in our application. For a full
|
-- This is where we define all of the routes in our application. For a full
|
||||||
-- explanation of the syntax, please see:
|
-- explanation of the syntax, please see:
|
||||||
-- http://www.yesodweb.com/book/routing-and-handlers
|
-- http://www.yesodweb.com/book/routing-and-handlers
|
||||||
|
@ -96,20 +91,14 @@ instance Yesod App where
|
||||||
master <- getYesod
|
master <- getYesod
|
||||||
mmsg <- getMessage
|
mmsg <- getMessage
|
||||||
|
|
||||||
-- muser <- maybeAuthPair
|
muser <- maybeAuthPair
|
||||||
mcurrentRoute <- getCurrentRoute
|
mcurrentRoute <- getCurrentRoute
|
||||||
|
|
||||||
-- Get the breadcrumbs, as defined in the YesodBreadcrumbs instance.
|
-- Get the breadcrumbs, as defined in the YesodBreadcrumbs instance.
|
||||||
(title, parents) <- breadcrumbs
|
(title, parents) <- breadcrumbs
|
||||||
|
|
||||||
-- Define the menu items of the header.
|
let navbarLeftMenuItems = leftMenuItems muser
|
||||||
let menuItems = []
|
navbarRightMenuItems = rightMenuItems muser
|
||||||
|
|
||||||
let navbarLeftMenuItems = [x | NavbarLeft x <- menuItems]
|
|
||||||
let navbarRightMenuItems = [x | NavbarRight x <- menuItems]
|
|
||||||
|
|
||||||
let navbarLeftFilteredMenuItems = [x | x <- navbarLeftMenuItems, menuItemAccessCallback x]
|
|
||||||
let navbarRightFilteredMenuItems = [x | x <- navbarRightMenuItems, menuItemAccessCallback x]
|
|
||||||
|
|
||||||
-- We break up the default layout into two components:
|
-- We break up the default layout into two components:
|
||||||
-- default-layout is the contents of the body tag, and
|
-- default-layout is the contents of the body tag, and
|
||||||
|
@ -154,6 +143,17 @@ instance Yesod App where
|
||||||
|
|
||||||
makeLogger = return . appLogger
|
makeLogger = return . appLogger
|
||||||
|
|
||||||
|
leftMenuItems, rightMenuItems :: Maybe (UserId, User) -> [MenuItem]
|
||||||
|
leftMenuItems _ = []
|
||||||
|
rightMenuItems = loggedOutItems `maybe` loggedInItems
|
||||||
|
where loggedOutItems =
|
||||||
|
[ "log in" `MenuItem` AuthR LoginR
|
||||||
|
]
|
||||||
|
loggedInItems (_id, user) =
|
||||||
|
[ userUsername user `MenuItem` HomeR
|
||||||
|
, "log out" `MenuItem` AuthR LogoutR
|
||||||
|
]
|
||||||
|
|
||||||
-- Define breadcrumbs.
|
-- Define breadcrumbs.
|
||||||
instance YesodBreadcrumbs App where
|
instance YesodBreadcrumbs App where
|
||||||
breadcrumb (AuthR _) = return ("login", Just HomeR)
|
breadcrumb (AuthR _) = return ("login", Just HomeR)
|
||||||
|
|
|
@ -7,12 +7,12 @@
|
||||||
|
|
||||||
<div #navbar .collapse.navbar-collapse>
|
<div #navbar .collapse.navbar-collapse>
|
||||||
<ul .navbar-nav.mr-auto>
|
<ul .navbar-nav.mr-auto>
|
||||||
$forall MenuItem label route _ <- navbarLeftFilteredMenuItems
|
$forall MenuItem label route <- navbarLeftMenuItems
|
||||||
<li .nav-item :Just route == mcurrentRoute:.active>
|
<li .nav-item :Just route == mcurrentRoute:.active>
|
||||||
<a .nav-link href=@{route}>#{label}
|
<a .nav-link href=@{route}>#{label}
|
||||||
|
|
||||||
<ul .navbar-nav>
|
<ul .navbar-nav>
|
||||||
$forall MenuItem label route _ <- navbarRightFilteredMenuItems
|
$forall MenuItem label route <- navbarRightMenuItems
|
||||||
<li .nav-item :Just route == mcurrentRoute:.active>
|
<li .nav-item :Just route == mcurrentRoute:.active>
|
||||||
<a .nav-link href=@{route}>#{label}
|
<a .nav-link href=@{route}>#{label}
|
||||||
$if not $ null parents
|
$if not $ null parents
|
||||||
|
|
Loading…
Reference in a new issue