Skip to content
Permalink
Browse files

posts

  • Loading branch information...
3v0k4 committed Jul 15, 2019
1 parent 8d89a71 commit a176ea0d10b63b9613cbfc5bbf86fbe264461111
Showing with 46 additions and 2 deletions.
  1. +1 −1 config/routes
  2. +30 −1 src/Handler/Posts.hs
  3. +15 −0 templates/posts.hamlet
@@ -13,4 +13,4 @@

/profile ProfileR GET
/ LandingR GET POST
/posts PostsR GET
/posts PostsR GET POST
@@ -1,6 +1,35 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE OverloadedStrings #-}

module Handler.Posts where

import Import

data Post =
Post { title :: Text, text :: Text }
deriving Show

postForm :: Form Post
postForm =
renderDivs $
Post <$> areq textField "Title" Nothing <*> areq textField "Text" Nothing

getPostsR :: Handler Html
getPostsR = error "Not yet implemented: getPostsR"
getPostsR = do
(widget, enctype) <- generateFormPost postForm
emptyLayout $ do
$(widgetFile "posts")

postPostsR :: Handler Html
postPostsR = do
((result, widget), enctype) <- runFormPost postForm
case result of
FormSuccess _ ->
redirect PostsR
_ ->
emptyLayout $ do
$(widgetFile "posts")
@@ -0,0 +1,15 @@
<h1>Posts

<div id="new-post">
<form method=post action=@{PostsR} enctype=#{enctype}>
^{widget}
<button>Post

<ul>
<li>
<h2>Title 1
<p>Text 1

<li>
<h2>Title 2
<p>Text 2

0 comments on commit a176ea0

Please sign in to comment.
You can’t perform that action at this time.