We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 933c2764 authored by Mitchell Rosen's avatar Mitchell Rosen

fixed edit/flag preview, some comment css

parent 83f4352d
......@@ -342,7 +342,11 @@ postDeleteComment comment_id =
-- | Handle a POST to an /edit URL. Returns Nothing if the comment was edited, or Just Widget
-- if there's a preview widget to display (per POST param "mode").
-- Permission checking should occur *PRIOR TO* this function.
postEditComment :: Entity User -> Entity Comment -> CommentHandlerInfo -> Handler (Maybe Widget)
postEditComment
:: Entity User
-> Entity Comment
-> CommentHandlerInfo
-> Handler (Maybe (Widget, Widget))
postEditComment user (Entity comment_id comment) comment_handler_info = do
((result, _), _) <- runFormPost (editCommentForm "")
case result of
......@@ -364,13 +368,13 @@ postEditComment user (Entity comment_id comment) comment_handler_info = do
(def { mod_flag_map = M.delete comment_id })
(getMaxDepthDefault 0)
True
return (Just (previewWidget form "post" comment_widget))
return (Just (comment_widget, form))
FormMissing -> error "Form missing."
FormFailure msgs -> error $ "Error submitting form: " ++ T.unpack (T.intercalate "\n" msgs)
-- | Handle a POST to a /flag URL.
-- Permission checking should occur *PRIOR TO* this function.
postFlagComment :: Entity User -> Entity Comment -> CommentHandlerInfo -> Handler (Maybe Widget)
postFlagComment :: Entity User -> Entity Comment -> CommentHandlerInfo -> Handler (Maybe (Widget, Widget))
postFlagComment user@(Entity user_id _) comment@(Entity comment_id _) comment_handler_info = do
((result, _), _) <- runFormPost (flagCommentForm Nothing Nothing)
case result of
......@@ -387,32 +391,9 @@ postFlagComment user@(Entity user_id _) comment@(Entity comment_id _) comment_ha
else alertDanger "error: another user flagged this just before you"
return Nothing
_ -> do
(form, _) <- generateFormPost $ flagCommentForm (Just (Just reasons)) (Just message)
let style_widget =
-- the CSS below styles this particular flagging submit
-- button. It would be ideal to have this in a more
-- generalized place so it can be reused in other flagging
-- buttons and be in just one place, but this works for
-- now.
toWidget [cassius|
.preview-action-button[type=submit]
background : dark-red
background-image : linear-gradient(#ee2700, #bd1000)
border-color: #a5022a
.preview-action-button[type=submit]:hover, .preview-action-button[type=submit]:focus, .preview-action-button[type=submit]:active
background : red
background-image : linear-gradient(#d22935, #a5022a)
|]
form_with_header =
[whamlet|
<h4>Code of Conduct Violation(s):
^{form}
|]
now <- liftIO getCurrentTime
let flagging = CommentFlagging now user_id comment_id message
let form = generateFlagCommentForm (Just (Just reasons)) (Just message)
flagging = CommentFlagging now user_id comment_id message
(comment_widget, _) <-
makeCommentActionWidget
can_flag
......@@ -423,7 +404,7 @@ postFlagComment user@(Entity user_id _) comment@(Entity comment_id _) comment_ha
(def { mod_flag_map = M.insert comment_id (flagging, reasons) })
(getMaxDepthDefault 0)
True
return (Just (style_widget <> previewWidget form_with_header "flag comment" comment_widget))
return (Just (comment_widget, form))
FormFailure errs -> flagFailure (T.intercalate ", " errs)
_ -> flagFailure "Form missing."
......
......@@ -575,7 +575,7 @@ postEditProjectCommentR project_handle comment_id = do
(projectCommentHandlerInfo (Just user) project_id project_handle)
>>= \case
Nothing -> redirect (ProjectCommentR project_handle comment_id) -- Edit made.
Just widget -> defaultLayout (projectDiscussionPage project_handle widget)
Just (widget, form) -> defaultLayout $ previewWidget form "edit" (projectDiscussionPage project_handle widget)
--------------------------------------------------------------------------------
-- /c/#CommentId/flag
......@@ -602,7 +602,7 @@ postFlagProjectCommentR project_handle comment_id = do
(projectCommentHandlerInfo (Just user) project_id project_handle)
>>= \case
Nothing -> redirect (ProjectDiscussionR project_handle)
Just widget -> defaultLayout (projectDiscussionPage project_handle widget)
Just (widget, form) -> defaultLayout $ previewWidget form "flag" (projectDiscussionPage project_handle widget)
--------------------------------------------------------------------------------
-- /c/#CommentId/reply
......@@ -778,7 +778,7 @@ getProjectDiscussion project_handle get_root_comments = do
project_handle
root_comments
def
(getMaxDepthDefault 0)
getMaxDepth
False
mempty
......
......@@ -228,7 +228,7 @@ getWikiDiscussionR' project_handle target get_root_comments = do
(wikiPageTarget page)
root_comments
def
(getMaxDepthDefault 0)
getMaxDepth
False
mempty
......
......@@ -121,6 +121,11 @@ makeWikiPageCommentActionWidget make_comment_action_widget project_handle target
get_max_depth
False
wikiDiscussionPage :: Text -> Text -> Widget -> Widget
wikiDiscussionPage project_handle target widget = do
$(widgetFile "wiki_discussion_wrapper")
toWidget $(cassiusFile "templates/comment.cassius")
--------------------------------------------------------------------------------
-- /
......@@ -144,9 +149,7 @@ getWikiCommentR project_handle target comment_id = do
Just (Entity user_id _) ->
runDB (userMaybeViewProjectCommentsDB user_id project_id (map entityKey (Tree.flatten comment_tree)))
defaultLayout $ do
$(widgetFile "wiki_discussion_wrapper")
toWidget $(cassiusFile "templates/comment.cassius")
defaultLayout (wikiDiscussionPage project_handle target widget)
--------------------------------------------------------------------------------
-- /claim
......@@ -161,9 +164,8 @@ getClaimWikiCommentR project_handle target comment_id = do
comment_id
def
getMaxDepth
defaultLayout $ do
$(widgetFile "wiki_discussion_wrapper")
toWidget $(cassiusFile "templates/comment.cassius")
defaultLayout (wikiDiscussionPage project_handle target widget)
postClaimWikiCommentR :: Text -> Text -> CommentId -> Handler Html
postClaimWikiCommentR project_handle target comment_id = do
......@@ -177,7 +179,7 @@ postClaimWikiCommentR project_handle target comment_id = do
(wikiPageCommentHandlerInfo (Just user) project_id project_handle target)
>>= \case
Nothing -> redirect (WikiCommentR project_handle target comment_id)
Just (widget, form) -> defaultLayout $ previewWidget form "claim" ($(widgetFile "wiki_discussion_wrapper"))
Just (widget, form) -> defaultLayout $ previewWidget form "claim" (wikiDiscussionPage project_handle target widget)
--------------------------------------------------------------------------------
-- /close
......@@ -192,9 +194,7 @@ getCloseWikiCommentR project_handle target comment_id = do
comment_id
def
getMaxDepth
defaultLayout $ do
$(widgetFile "wiki_discussion_wrapper")
toWidget $(cassiusFile "templates/comment.cassius")
defaultLayout (wikiDiscussionPage project_handle target widget)
postCloseWikiCommentR :: Text -> Text -> CommentId -> Handler Html
postCloseWikiCommentR project_handle target comment_id = do
......@@ -208,7 +208,7 @@ postCloseWikiCommentR project_handle target comment_id = do
(wikiPageCommentHandlerInfo (Just user) project_id project_handle target)
>>= \case
Nothing -> redirect (WikiCommentR project_handle target comment_id)
Just (widget, form) -> defaultLayout $ previewWidget form "close" ($(widgetFile "wiki_discussion_wrapper"))
Just (widget, form) -> defaultLayout $ previewWidget form "close" (wikiDiscussionPage project_handle target widget)
--------------------------------------------------------------------------------
-- /delete
......@@ -223,9 +223,7 @@ getDeleteWikiCommentR project_handle target comment_id = do
comment_id
def
getMaxDepth
defaultLayout $ do
$(widgetFile "wiki_discussion_wrapper")
toWidget $(cassiusFile "templates/comment.cassius")
defaultLayout (wikiDiscussionPage project_handle target widget)
postDeleteWikiCommentR :: Text -> Text -> CommentId -> Handler Html
postDeleteWikiCommentR project_handle target comment_id = do
......@@ -250,9 +248,7 @@ getEditWikiCommentR project_handle target comment_id = do
comment_id
def
getMaxDepth
defaultLayout $ do
$(widgetFile "wiki_discussion_wrapper")
toWidget $(cassiusFile "templates/comment.cassius")
defaultLayout (wikiDiscussionPage project_handle target widget)
postEditWikiCommentR :: Text -> Text -> CommentId -> Handler Html
postEditWikiCommentR project_handle target comment_id = do
......@@ -265,7 +261,7 @@ postEditWikiCommentR project_handle target comment_id = do
(wikiPageCommentHandlerInfo (Just user) project_id project_handle target)
>>= \case
Nothing -> redirect (WikiCommentR project_handle target comment_id) -- Edit made.
Just widget -> defaultLayout $(widgetFile "wiki_discussion_wrapper") -- Previewing edit.
Just (widget, form) -> defaultLayout $ previewWidget form "edit" (wikiDiscussionPage project_handle target widget)
--------------------------------------------------------------------------------
-- /flag
......@@ -280,9 +276,7 @@ getFlagWikiCommentR project_handle target comment_id = do
comment_id
def
getMaxDepth
defaultLayout $ do
$(widgetFile "wiki_discussion_wrapper")
toWidget $(cassiusFile "templates/comment.cassius")
defaultLayout (wikiDiscussionPage project_handle target widget)
postFlagWikiCommentR :: Text -> Text -> CommentId -> Handler Html
postFlagWikiCommentR project_handle target comment_id = do
......@@ -295,7 +289,7 @@ postFlagWikiCommentR project_handle target comment_id = do
(wikiPageCommentHandlerInfo (Just user) project_id project_handle target)
>>= \case
Nothing -> redirect (WikiDiscussionR project_handle target)
Just widget -> defaultLayout $(widgetFile "wiki_discussion_wrapper")
Just (widget, form) -> defaultLayout $ previewWidget form "flag" (wikiDiscussionPage project_handle target widget)
--------------------------------------------------------------------------------
-- /moderate TODO: rename to /approve
......@@ -310,9 +304,7 @@ getApproveWikiCommentR project_handle target comment_id = do
comment_id
def
getMaxDepth
defaultLayout $ do
$(widgetFile "wiki_discussion_wrapper")
toWidget $(cassiusFile "templates/comment.cassius")
defaultLayout (wikiDiscussionPage project_handle target widget)
postApproveWikiCommentR :: Text -> Text -> CommentId -> Handler Html
postApproveWikiCommentR project_handle target comment_id = do
......@@ -335,9 +327,7 @@ getReplyWikiCommentR project_handle target comment_id = do
comment_id
def
getMaxDepth
defaultLayout $ do
$(widgetFile "wiki_discussion_wrapper")
toWidget $(cassiusFile "templates/comment.cassius")
defaultLayout (wikiDiscussionPage project_handle target widget)
postReplyWikiCommentR :: Text -> Text -> CommentId -> Handler Html
postReplyWikiCommentR project_handle target parent_id = do
......@@ -350,7 +340,7 @@ postReplyWikiCommentR project_handle target parent_id = do
(wikiPageDiscussion page)
(makeProjectCommentActionPermissionsMap (Just user) project_handle) >>= \case
Left _ -> redirect (WikiCommentR project_handle target parent_id)
Right (widget, form) -> defaultLayout $ previewWidget form "post" ($(widgetFile "wiki_discussion_wrapper"))
Right (widget, form) -> defaultLayout $ previewWidget form "post" (wikiDiscussionPage project_handle target widget)
--------------------------------------------------------------------------------
-- /rethread
......@@ -365,9 +355,7 @@ getRethreadWikiCommentR project_handle target comment_id = do
comment_id
def
getMaxDepth
defaultLayout $ do
$(widgetFile "wiki_discussion_wrapper")
toWidget $(cassiusFile "templates/comment.cassius")
defaultLayout (wikiDiscussionPage project_handle target widget)
postRethreadWikiCommentR :: Text -> Text -> CommentId -> Handler Html
postRethreadWikiCommentR project_handle target comment_id = do
......@@ -388,9 +376,7 @@ getRetractWikiCommentR project_handle target comment_id = do
comment_id
def
getMaxDepth
defaultLayout $ do
$(widgetFile "wiki_discussion_wrapper")
toWidget $(cassiusFile "templates/comment.cassius")
defaultLayout (wikiDiscussionPage project_handle target widget)
postRetractWikiCommentR :: Text -> Text -> CommentId -> Handler Html
postRetractWikiCommentR project_handle target comment_id = do
......@@ -404,7 +390,7 @@ postRetractWikiCommentR project_handle target comment_id = do
(wikiPageCommentHandlerInfo (Just user) project_id project_handle target)
>>= \case
Nothing -> redirect (WikiCommentR project_handle target comment_id)
Just (widget, form) -> defaultLayout $ previewWidget form "retract" ($(widgetFile "wiki_discussion_wrapper"))
Just (widget, form) -> defaultLayout $ previewWidget form "retract" (wikiDiscussionPage project_handle target widget)
--------------------------------------------------------------------------------
-- /tags
......
......@@ -13,6 +13,7 @@ module View.Comment
, createCommentTagForm
, editCommentForm
, flagCommentForm
, generateFlagCommentForm
, newCommentTagForm
, rethreadCommentForm
, retractCommentForm
......@@ -178,6 +179,25 @@ flagCommentFormWidget def_reasons def_message = do
<button type="submit" name="mode" value="preview">preview flag message
|]
generateFlagCommentForm :: Maybe (Maybe [FlagReason]) -> Maybe (Maybe Markdown) -> Widget
generateFlagCommentForm reasons message = do
(form, _) <- handlerToWidget (generateFormPost $ flagCommentForm reasons message)
[whamlet|
<h4>Code of Conduct Violation(s):
^{form}
|]
toWidget [cassius|
.preview-action-button[type=submit]
background : dark-red
background-image : linear-gradient(#ee2700, #bd1000)
border-color: #a5022a
.preview-action-button[type=submit]:hover, .preview-action-button[type=submit]:focus, .preview-action-button[type=submit]:active
background : red
background-image : linear-gradient(#d22935, #a5022a)
|]
deleteCommentFormWidget :: Widget
deleteCommentFormWidget =
[whamlet|
......@@ -206,11 +226,8 @@ expandCommentWidget num_replies new_max_depth = do
NoMaxDepth -> (cur_route, [])
MaxDepth n -> (cur_route, [("maxdepth", T.pack (show n))])
[whamlet|
<br>
<br>
<em>
<a href="@?{new_route}">
#{num_replies} more #{plural num_replies "reply" "replies"}
<a .expand href="@?{new_route}">
#{num_replies} more #{plural num_replies "reply" "replies"}
|]
-- | An entire comment forest.
......@@ -325,7 +342,7 @@ commentTreeWidget'
let num_children = length children
inner_widget =
form_under_root_comment <>
if MaxDepth depth > max_depth && num_children > 0
if MaxDepth depth >= max_depth && num_children > 0
then expandCommentWidget num_children (addMaxDepth max_depth 2) -- FIXME(mitchell): arbitrary '2' here
else forM_ children $ \child ->
commentTreeWidget'
......
.comment
padding : 0 0.5em
padding : 0 1em
margin-top : 0.5em
border-bottom-left-radius: 0.6em
border-bottom-left-radius : 0.6em
font-size : small
.comment p, .comment ul, .comment ol, .comment h1, .comment h2, .comment h3, .comment h4, .comment h5, .comment h6
margin : 0
......@@ -25,7 +26,6 @@
.comment-head-item, .comment-action
display : inline-block
font-size : small
.comment-actions
margin-bottom : 0.5em
......@@ -35,7 +35,11 @@
margin-right : 1px
.comment-body
font-size : smaller
font-size : 1.12em
margin : 0.5em 0
.inner-widget
margin-top: 1em
.awaiting-approval
color : green
......@@ -89,5 +93,8 @@
margin : .5em 0
display : table
.expand
font-style : italic
.preview a
pointer-events: none
......@@ -131,4 +131,5 @@
<a href="@{comment_route_unclaim comment_id}">
unclaim
^{inner_widget}
<div .inner-widget>
^{inner_widget}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment