Skip to content

Instantly share code, notes, and snippets.

@rje
Created December 1, 2016 23:50
Show Gist options
  • Select an option

  • Save rje/ccee4798be5d66818592f8b8421bd9ff to your computer and use it in GitHub Desktop.

Select an option

Save rje/ccee4798be5d66818592f8b8421bd9ff to your computer and use it in GitHub Desktop.
getHomeR :: Handler Html
getHomeR = do
docCount <- runDB $ count ([] :: [Filter Doc])
((_, docWidget), _) <- runFormPost addDocForm
((_, searchWidget), _) <- runFormGet searchForm
let docs = if docCount == 1
then "There is currently 1 document."
else "There are currently " ++ show docCount ++ " documents."
defaultLayout
[whamlet|
<p>Welcome to the search application. #{docs}
<form method=post action=@{AddDocR}>
<table>
^{docWidget}
<tr>
<td colspan=3>
<input type=submit value="Add document">
<form method=get action=@{SearchR}>
^{searchWidget}
<input type=submit value=Search>
|]
postAddDocR :: Handler Html
postAddDocR = do
((res, docWidget), _) <- runFormPost addDocForm
case res of
FormSuccess doc -> do
docid <- runDB $ insert doc
setMessage "Document added"
redirect $ DocR docid
_ -> defaultLayout
[whamlet|
<form method=post action=@{AddDocR}>
<table>
^{docWidget}
<tr>
<td colspan=3>
<input type=submit value="Add document">
|]
getDocR :: DocId -> Handler Html
getDocR docid = do
doc <- runDB $ get404 docid
defaultLayout
[whamlet|
<h1>#{docTitle doc}
<div .content>#{docContent doc}
|]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment