From 7ba4518587eaae311aa7a22bc012846934382410 Mon Sep 17 00:00:00 2001 From: Vyrtsev Mikhail Date: Wed, 16 Jan 2019 23:37:16 +0300 Subject: [PATCH] disable comment editing if it has reply --- web/app/components/comment/comment.jsx | 3 ++- web/app/components/input/input.jsx | 24 ++++++++++++++++++------ web/app/components/thread/thread.jsx | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/web/app/components/comment/comment.jsx b/web/app/components/comment/comment.jsx index d59e0b70..abd35664 100644 --- a/web/app/components/comment/comment.jsx +++ b/web/app/components/comment/comment.jsx @@ -391,6 +391,7 @@ export default class Comment extends Component { const lowCommentScore = config.low_score; const votingDisabledReason = this.getVoteDisabledReason(); const isVotingDisabled = votingDisabledReason !== null; + const editable = data.repliesCount === 0 && !!editTimeLeft; const o = { ...data, @@ -588,7 +589,7 @@ export default class Comment extends Component { !mods.disabled && !!o.orig && isCurrentUser && - (!!editTimeLeft || isEditing) && + (editable || isEditing) && mods.view !== 'user' && [ { - this.setState({ isErrorShown: true }); + .catch(e => { + if ( + e.response && + e.response.data && + typeof e.response.data.error === 'string' && + e.response.data.error.indexOf("parent comment with reply can't be edited") === 0 + ) { + this.setState({ isErrorShown: true, errorMessage: 'Comment has reply, editing is not possible' }); + return; + } + this.setState({ isErrorShown: true, errorMessage: null }); }) .finally(() => this.setState({ isDisabled: false })); } @@ -98,19 +109,20 @@ export default class Input extends Component { if (!text || !text.trim()) return; - this.setState({ isErrorShown: false }); + this.setState({ isErrorShown: false, errorMessage: null }); api .getPreview({ text }) .then(preview => this.setState({ preview })) .catch(() => { - this.setState({ isErrorShown: true }); + this.setState({ isErrorShown: true, errorMessage: null }); }); } - render(props, { isDisabled, isErrorShown, preview, maxLength, text }) { + render(props, { isDisabled, isErrorShown, errorMessage, preview, maxLength, text }) { const charactersLeft = maxLength - text.length; - const { mods = {}, errorMessage, userId } = props; + const { mods = {}, userId } = props; + errorMessage = props.errorMessage || errorMessage; return (
diff --git a/web/app/components/thread/thread.jsx b/web/app/components/thread/thread.jsx index 1b2342af..af7240f9 100644 --- a/web/app/components/thread/thread.jsx +++ b/web/app/components/thread/thread.jsx @@ -31,7 +31,7 @@ class Thread extends Component { aria-expanded={!collapsed} >