@@ -3,11 +3,12 @@ import { useContext, useEffect, useState } from "react";
33import { Mention } from "./IComment" ;
44import { Text } from "@fluentui/react/lib/Text" ;
55import { LivePersona } from "../../../LivePersona" ;
6- import { AppContext } from " ../../common" ;
7- import regexifyString from " regexify-string" ;
8- import { Stack } from " @fluentui/react/lib/Stack" ;
9- import { isArray , isObject } from " lodash" ;
6+ import { AppContext , URL_REGEX } from ' ../../common' ;
7+ import regexifyString from ' regexify-string' ;
8+ import { Stack } from ' @fluentui/react/lib/Stack' ;
9+ import { isArray , isObject } from ' lodash' ;
1010import he from 'he' ;
11+ import { Link } from '@fluentui/react' ;
1112export interface ICommentTextProps {
1213 text : string ;
1314 mentions : Mention [ ] ;
@@ -46,26 +47,55 @@ export const CommentText: React.FunctionComponent<ICommentTextProps> = (
4647 setCommentText ( result ) ;
4748 } , [ ] ) ;
4849
50+ const convertTextToLinksAndText = (
51+ text : string
52+ ) : ( string | JSX . Element ) [ ] => {
53+ const parts = text . split ( URL_REGEX ) ;
54+ return parts . map ( ( part , index ) => {
55+ if ( part . match ( URL_REGEX ) ) {
56+ return (
57+ < Link
58+ key = { index }
59+ href = { part }
60+ target = "_blank"
61+ rel = "noopener noreferrer"
62+ style = { { color : theme . link } }
63+ >
64+ { part }
65+ </ Link >
66+ ) ;
67+ }
68+ return part ;
69+ } ) ;
70+ } ;
71+
4972 return (
5073 < >
5174 < Stack wrap horizontal horizontalAlign = "start" verticalAlign = "center" >
5275 { isArray ( commentText ) ? (
53- ( commentText as any [ ] ) . map ( ( el , i ) => { // eslint-disable-line @typescript-eslint/no-explicit-any
76+ ( commentText as any [ ] ) . map ( ( el , i ) => {
77+ // eslint-disable-line @typescript-eslint/no-explicit-any
5478 if ( isObject ( el ) ) {
55- return < span key = { i } style = { { paddingRight : 5 } } > { el } </ span > ;
79+ return (
80+ < span key = { i } style = { { paddingRight : 5 } } >
81+ { el }
82+ </ span >
83+ ) ;
5684 } else {
5785 const _el : string = el . trim ( ) ;
5886 if ( _el . length ) {
5987 return (
6088 < Text style = { { paddingRight : 5 } } variant = "small" key = { i } >
61- { he . decode ( _el ) }
89+ { convertTextToLinksAndText ( he . decode ( _el ) ) }
6290 </ Text >
6391 ) ;
6492 }
6593 }
6694 } )
6795 ) : (
68- < Text variant = "small" > { he . decode ( commentText ) } </ Text >
96+ < Text variant = "small" >
97+ { convertTextToLinksAndText ( he . decode ( commentText ) ) }
98+ </ Text >
6999 ) }
70100 </ Stack >
71101 </ >
0 commit comments