uebung2017-9/Timeline.hs
2017-06-29 17:08:27 +02:00

35 lines
1.1 KiB
Haskell

{-# 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)