From 2e7055622ea564285d25154ce4dfedf0e2f7eb64 Mon Sep 17 00:00:00 2001 From: Simon Backx Date: Fri, 22 Jul 2022 17:38:28 +0200 Subject: [PATCH] Fixed reply box redrawing when clicking the button again refs https://github.com/TryGhost/Team/issues/1710 Was caused by: mouseDown triggered on Reply button -> editor blurred -> editor closed itself -> onClick on reply opened the form again --- apps/comments-ui/src/components/Comment.js | 12 ++++++++++-- apps/comments-ui/src/components/Form.js | 13 +++++-------- apps/comments-ui/src/components/Reply.js | 7 ++++++- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/apps/comments-ui/src/components/Comment.js b/apps/comments-ui/src/components/Comment.js index 702e85a8ab..639ca66491 100644 --- a/apps/comments-ui/src/components/Comment.js +++ b/apps/comments-ui/src/components/Comment.js @@ -17,10 +17,18 @@ const Comment = (props) => { setIsInEditMode(current => !current); }; + const closeEditMode = () => { + setIsInEditMode(false); + }; + const toggleReplyMode = () => { setIsInReplyMode(current => !current); }; + const closeReplyMode = () => { + setIsInReplyMode(false); + }; + const {admin, avatarSaturation, member, commentsEnabled} = useContext(AppContext); const comment = props.comment; const hasReplies = comment.replies && comment.replies.length > 0; @@ -41,7 +49,7 @@ const Comment = (props) => { if (isInEditMode) { return ( -
+ ); } else { return ( @@ -82,7 +90,7 @@ const Comment = (props) => { leaveTo="opacity-0" >
- +
diff --git a/apps/comments-ui/src/components/Form.js b/apps/comments-ui/src/components/Form.js index 868b1953e1..70a17e8c02 100644 --- a/apps/comments-ui/src/components/Form.js +++ b/apps/comments-ui/src/components/Form.js @@ -141,10 +141,10 @@ const Form = (props) => { editor.on('blur', () => { if (editor?.isEmpty) { setFormOpen(false); - if (props.isReply && props.toggle) { + if (props.isReply && props.close) { // TODO: we cannot toggle the form when this happens, because when the member doesn't have a name we'll always loose focus to input the name... // Need to find a different way for this behaviour - props.toggle(); + props.close(); } } }); @@ -177,10 +177,7 @@ const Form = (props) => { // Clear message and blur on success editor.chain().clearContent().blur().run(); - props.toggle(); - - setFormOpen(false); - props.toggle(); + props.close(); } catch (e) { // eslint-disable-next-line no-console console.error(e); @@ -195,7 +192,7 @@ const Form = (props) => { parent: props.parent }); - props.toggle(); + props.close(); } else { try { // Send comment to server @@ -291,7 +288,7 @@ const Form = (props) => { transition-[opacity] duration-150 "> {props.isEdit && - } + } ) : null; }