2017-10-08 01:51:48 -04:00
|
|
|
{-# LANGUAGE NoImplicitPrelude #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE TemplateHaskell #-}
|
2017-10-08 18:02:42 -04:00
|
|
|
module Widget.Entry ( entryR, hEntry ) where
|
2017-10-08 01:51:48 -04:00
|
|
|
|
|
|
|
import Import
|
|
|
|
|
2017-10-10 04:45:31 -04:00
|
|
|
import Database.Esqueleto ( (^.) )
|
|
|
|
import qualified Database.Esqueleto as E
|
2017-10-08 18:55:34 -04:00
|
|
|
import Data.Time.Format ( defaultTimeLocale, formatTime, iso8601DateFormat )
|
|
|
|
import Data.Time.Format.Human ( humanReadableTime )
|
|
|
|
|
2017-10-09 04:54:58 -04:00
|
|
|
data FormattedTime = FormattedTime
|
|
|
|
{ timeUnfriendly :: String
|
|
|
|
, timeFriendly :: String
|
|
|
|
} deriving Eq
|
2017-10-08 18:55:34 -04:00
|
|
|
|
|
|
|
toFormattedTime :: MonadIO m => UTCTime -> m FormattedTime
|
|
|
|
toFormattedTime time = FormattedTime (unfriendly time) <$> friendly time
|
|
|
|
where unfriendly = formatTime defaultTimeLocale . iso8601DateFormat . Just $ "%H:%M:%S%z"
|
|
|
|
friendly = liftIO . humanReadableTime
|
|
|
|
|
2017-10-08 18:02:42 -04:00
|
|
|
entryR :: Entity Entry -> Route App
|
|
|
|
entryR (Entity entryId entry) = EntryR (entryKind entry) entryId (entrySlug entry)
|
|
|
|
|
2017-10-08 01:51:48 -04:00
|
|
|
hEntry :: Entity Entry -> Widget
|
|
|
|
hEntry (Entity entryId entry) = do
|
2017-10-08 18:55:34 -04:00
|
|
|
published <- toFormattedTime . entryPublished $ entry
|
|
|
|
updated <- toFormattedTime . entryUpdated $ entry
|
2017-10-10 04:45:31 -04:00
|
|
|
posses <- handlerToWidget . runDB . E.select . E.from $ \(syndication `E.InnerJoin` profile `E.InnerJoin` site) -> do
|
|
|
|
E.on $ profile ^. ProfileSiteId E.==. site ^. SiteId
|
|
|
|
E.on $ syndication ^. SyndicationProfileId E.==. profile ^. ProfileId
|
|
|
|
E.where_ $ syndication ^. SyndicationEntryId E.==. E.val entryId
|
2017-10-10 07:41:49 -04:00
|
|
|
E.orderBy [E.asc $ site ^. SiteName]
|
2017-10-10 04:45:31 -04:00
|
|
|
return (syndication ^. SyndicationUrl, site ^. SiteIcon, E.coalesceDefault [profile ^. ProfileDisplayName] (profile ^. ProfileUsername))
|
2017-10-08 01:51:48 -04:00
|
|
|
maybeAuthor <- handlerToWidget . runDB . get . entryAuthorId $ entry
|
|
|
|
$(widgetFile "mf2/h-entry")
|