From 1c4212f5d02670c5969ff21bcac177ec02a62d6f Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Fri, 6 Oct 2017 14:23:42 +1100 Subject: [PATCH] Bring back menu items for logging in and out --- src/Foundation.hs | 28 ++++++++++++++-------------- templates/default-layout.hamlet | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Foundation.hs b/src/Foundation.hs index 8fbd694..f9d882a 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -36,13 +36,8 @@ data App = App data MenuItem = MenuItem { menuItemLabel :: Text , 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 -- explanation of the syntax, please see: -- http://www.yesodweb.com/book/routing-and-handlers @@ -96,20 +91,14 @@ instance Yesod App where master <- getYesod mmsg <- getMessage - -- muser <- maybeAuthPair + muser <- maybeAuthPair mcurrentRoute <- getCurrentRoute -- Get the breadcrumbs, as defined in the YesodBreadcrumbs instance. (title, parents) <- breadcrumbs - -- Define the menu items of the header. - let menuItems = [] - - 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] + let navbarLeftMenuItems = leftMenuItems muser + navbarRightMenuItems = rightMenuItems muser -- We break up the default layout into two components: -- default-layout is the contents of the body tag, and @@ -154,6 +143,17 @@ instance Yesod App where 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. instance YesodBreadcrumbs App where breadcrumb (AuthR _) = return ("login", Just HomeR) diff --git a/templates/default-layout.hamlet b/templates/default-layout.hamlet index abd0e59..795e798 100644 --- a/templates/default-layout.hamlet +++ b/templates/default-layout.hamlet @@ -7,12 +7,12 @@