uebung2017-9/Timeline.hs

35 lines
1.1 KiB
Haskell
Raw Normal View History

2017-06-29 15:08:27 +00:00
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Handler.Timeline where
import Import
getTimelineR :: Handler Html
getTimelineR = do
(uid, user) <- requireAuthPair
posts <- runDB $ selectList [PostUserId ==. uid] [Desc PostCreated]
(postWidget, postEnctype) <- generateFormPost (postForm Nothing uid)
let userName :: Text
userName = userIdent user
defaultLayout $ do
setTitle . toHtml $ userName <> "'s Timeline"
$(widgetFile "timeline")
-- TODO: Implementieren Sie ein Verhalten zum Speichern des Posts.
-- Nützliche Funktionen: runFormPost.
postTimelineR :: Handler Html
postTimelineR = do
getTimelineR
postForm :: Maybe PostId -> UserId -> Form Post
postForm p u = renderDivs $ Post
<$> pure u
<*> areq textField "Post" (Just "Post content")
<*> pure p
<*> lift (liftIO getCurrentTime)