Create an h-card widget and display my h-card on the homepage - needs more info but it's a good start

This commit is contained in:
Danielle McLean 2017-10-03 00:52:14 +11:00
parent 5eccafa9c2
commit 006264e77f
Signed by: 00dani
GPG key ID: 3844A6973C6058F1
6 changed files with 27 additions and 2 deletions

View file

@ -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

View file

@ -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
}

View file

@ -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")

12
src/Widget/Hcard.hs Normal file
View file

@ -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")

5
templates/hcard.hamlet Normal file
View file

@ -0,0 +1,5 @@
<div .card.h-card>
$maybe avatar <- userAvatar user
<img .card-img-top.u-photo src=@{img avatar} alt="Avatar for #{userFullName user}">
<div .card-body>
<h4 .card-title.p-name>#{userFullName user}

View file

@ -0,0 +1 @@
^{hcard user}