Rename the h-card implementation to match up with the naming of h-feed and h-entry
This commit is contained in:
parent
4b7a8a7198
commit
3ff560e07e
5 changed files with 6 additions and 6 deletions
40
src/Widget/Card.hs
Normal file
40
src/Widget/Card.hs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
{-# LANGUAGE NoImplicitPrelude #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
module Widget.Card ( hCard ) where
|
||||
|
||||
import Import
|
||||
import Data.Maybe (fromJust)
|
||||
import qualified Data.Map as M
|
||||
import qualified Data.Text as T
|
||||
import qualified Network.Libravatar as L
|
||||
|
||||
libravatar :: (MonadIO m) => User -> m (Maybe Text)
|
||||
libravatar = liftIO . flip L.avatarUrl opts . L.Email . userEmail
|
||||
where opts = def { L.optSecure = True, L.optSize = L.Size 512, L.optTryGravatar = False }
|
||||
|
||||
entityToTuple :: Entity t -> (Key t, t)
|
||||
entityToTuple (Entity key value) = (key, value)
|
||||
|
||||
arrangeProfiles :: M.Map (Key Site) Site -> [Profile] -> [(Site,Profile)]
|
||||
arrangeProfiles sites profiles = sortBy icon $ zip profileSites profiles
|
||||
where findSite = fromJust . flip M.lookup sites . profileSiteId
|
||||
profileSites = findSite <$> profiles
|
||||
icon = comparing $ siteIcon . fst
|
||||
|
||||
prettyPgp :: PgpKey -> Text
|
||||
prettyPgp = T.unwords . T.chunksOf 4 . pgpKeyFingerprint
|
||||
|
||||
routeFromPgp :: PgpKey -> Route App
|
||||
routeFromPgp PgpKey { pgpKeyFingerprint = f } = staticR ["pgp", T.takeEnd 8 f ++ ".asc"]
|
||||
|
||||
hCard :: Entity User -> Widget
|
||||
hCard (Entity userId user) = do
|
||||
maybeAvatar <- libravatar user
|
||||
mcurrentRoute <- getCurrentRoute
|
||||
userProfiles <- handlerToWidget . runDB $ do
|
||||
profiles <- map entityVal <$> selectList [ProfileUserId ==. userId] []
|
||||
sites <- M.fromList . map entityToTuple <$> selectList [SiteId <-. (profileSiteId <$> profiles)] []
|
||||
return $ arrangeProfiles sites profiles
|
||||
pgpKeys <- handlerToWidget . runDB $ map entityVal <$> selectList [PgpKeyUserId ==. userId] []
|
||||
$(widgetFile "mf2/h-card")
|
||||
Loading…
Add table
Add a link
Reference in a new issue