@@ -13,7 +13,7 @@ import HashtagPaste from './hashtagPaste';
1313import FileRejections from './fileRejections' ;
1414import DropzoneUploadStatus from './uploadStatus' ;
1515import { DROPZONE_SETTINGS } from '../../config' ;
16- import { formatUserNamesToLink } from '../../utils/htmlFromMarkdown' ;
16+ import { formatUserNamesToLink , markdownFromHtml } from '../../utils/htmlFromMarkdown' ;
1717import { iconConfig } from './editorIconConfig' ;
1818import messages from './messages' ;
1919import { CurrentUserAvatar } from '../user/avatar' ;
@@ -32,11 +32,13 @@ function CommentInputField({
3232 isShowUserPicture = false ,
3333 placeholderMsg = messages . leaveAComment ,
3434 markdownTextareaProps = { } ,
35+ enableMappersHashtag = false ,
3536} : Object ) {
3637 const token = useSelector ( ( state ) => state . auth . token ) ;
3738 const textareaRef = useRef ( ) ;
3839 const fileInputRef = useRef ( null ) ;
3940 const isBundle = useRef ( false ) ;
41+ const lastConvertedRef = useRef ( null ) ;
4042 const [ isShowPreview , setIsShowPreview ] = useState ( false ) ;
4143
4244 const appendImgToComment = ( url ) => setComment ( `${ comment } \n\n` ) ;
@@ -149,7 +151,21 @@ function CommentInputField({
149151 sessionStorage . setItem ( sessionkey , comment ) ;
150152 } , [ comment , sessionkey ] ) ;
151153
152- console . log ( comment , 'comment' ) ;
154+ useEffect ( ( ) => {
155+ if (
156+ comment &&
157+ comment !== lastConvertedRef . current &&
158+ / < \/ ? (?: p | d i v | h [ 1 - 6 ] | u l | o l | l i | b r | s t r o n g | e m | a | t a b l e | t h e a d | t b o d y | t r | t h | t d | b l o c k q u o t e | p r e | c o d e | s p a n ) [ \s > ] / i. test ( comment ) &&
159+ document . activeElement !== textareaRef . current ?. textarea
160+ ) {
161+ const converted = markdownFromHtml ( comment ) ;
162+ if ( converted !== comment ) {
163+ lastConvertedRef . current = converted ;
164+ setComment ( converted ) ;
165+ }
166+ }
167+ // eslint-disable-next-line react-hooks/exhaustive-deps
168+ } , [ comment ] ) ;
153169
154170 return (
155171 < div { ...getRootProps ( ) } >
@@ -291,6 +307,12 @@ function CommentInputField({
291307 < HashtagPaste text = { comment } setFn = { setComment } hashtag = "#contributors" />
292308 </ >
293309 ) }
310+ { enableMappersHashtag && (
311+ < >
312+ < span > , </ span >
313+ < HashtagPaste text = { comment } setFn = { setComment } hashtag = "#mappers" />
314+ </ >
315+ ) }
294316 </ span >
295317 ) }
296318 < DropzoneUploadStatus
0 commit comments