From 006264e77f82b863ce97b8e7598f72f2c2d840f3 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Tue, 3 Oct 2017 00:52:14 +1100 Subject: [PATCH] Create an h-card widget and display my h-card on the homepage - needs more info but it's a good start --- config/models | 2 ++ src/Foundation.hs | 4 +++- src/Handler/Home.hs | 5 ++++- src/Widget/Hcard.hs | 12 ++++++++++++ templates/hcard.hamlet | 5 +++++ templates/home.hamlet | 1 + 6 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/Widget/Hcard.hs create mode 100644 templates/hcard.hamlet diff --git a/config/models b/config/models index 297ae86..08cb988 100644 --- a/config/models +++ b/config/models @@ -1,5 +1,7 @@ User ident Text sqltype=varchar(255) + fullName Text sqltype=varchar(500) + avatar Text Maybe sqltype=varchar(255) default=NULL password Text Maybe sqltype=varchar(255) default=NULL UniqueUser ident deriving Typeable diff --git a/src/Foundation.hs b/src/Foundation.hs index 1fc9372..1a64380 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -217,7 +217,9 @@ instance YesodAuth App where case x of Just (Entity uid _) -> return $ Authenticated uid Nothing -> Authenticated <$> insert User - { userIdent = credsIdent creds + { userAvatar = Nothing + , userIdent = credsIdent creds + , userFullName = "" , userPassword = Nothing } diff --git a/src/Handler/Home.hs b/src/Handler/Home.hs index 598de27..c6a7a3a 100644 --- a/src/Handler/Home.hs +++ b/src/Handler/Home.hs @@ -6,6 +6,9 @@ module Handler.Home where import Import +import Widget.Hcard (hcard) getHomeR :: Handler Html -getHomeR = defaultLayout $(widgetFile "home") +getHomeR = do + (Entity _ user) <- runDB . getBy404 $ UniqueUser "dani" + defaultLayout $(widgetFile "home") diff --git a/src/Widget/Hcard.hs b/src/Widget/Hcard.hs new file mode 100644 index 0000000..3b4b1de --- /dev/null +++ b/src/Widget/Hcard.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} +module Widget.Hcard (hcard) where + +import Import + +img :: Text -> Route App +img file = StaticR . flip StaticRoute [] $ ["img", file] + +hcard :: User -> Widget +hcard user = $(widgetFile "hcard") diff --git a/templates/hcard.hamlet b/templates/hcard.hamlet new file mode 100644 index 0000000..1575ae8 --- /dev/null +++ b/templates/hcard.hamlet @@ -0,0 +1,5 @@ +
+ $maybe avatar <- userAvatar user + Avatar for #{userFullName user} +
+

#{userFullName user} diff --git a/templates/home.hamlet b/templates/home.hamlet index e69de29..47ca208 100644 --- a/templates/home.hamlet +++ b/templates/home.hamlet @@ -0,0 +1 @@ +^{hcard user}