-
-
Notifications
You must be signed in to change notification settings - Fork 797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(AlbumDetails): Extract urls from comments and link them to their corresponding sites - #1053 #1570
feat(AlbumDetails): Extract urls from comments and link them to their corresponding sites - #1053 #1570
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import React, { useMemo, useCallback } from 'react' | ||
|
||
import { | ||
Card, | ||
CardContent, | ||
|
@@ -101,6 +102,10 @@ const useStyles = makeStyles( | |
}, | ||
externalLinks: { | ||
marginTop: theme.spacing(1.5), | ||
color: theme.palette.text.primary, | ||
'&:hover': { | ||
color: theme.palette.primary.dark, | ||
}, | ||
}, | ||
}), | ||
{ | ||
|
@@ -112,15 +117,32 @@ const AlbumComment = ({ record }) => { | |
const classes = useStyles() | ||
const [expanded, setExpanded] = React.useState(false) | ||
|
||
const reqClassName = classes.externalLinks | ||
console.log(reqClassName) | ||
const linkify = useCallback( | ||
(text) => { | ||
// eslint-disable-next-line | ||
const urlRegex = | ||
// eslint-disable-next-line | ||
/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi | ||
return text.replace(urlRegex, function (url) { | ||
return ( | ||
'<a class=' + reqClassName + ' href="' + url + '">' + url + '</a>' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the vanilla anchor tag works, but to ensure continuity in how links appear and behave (e.g. :visited), I think a More about accessibility in links: https://www.smashingmagazine.com/2021/12/designing-better-links-websites-emails-guideline/#link-accessibility |
||
) | ||
}) | ||
}, | ||
[reqClassName] | ||
) | ||
|
||
const lines = record.comment.split('\n') | ||
const formatted = useMemo(() => { | ||
return lines.map((line, idx) => ( | ||
<span key={record.id + '-comment-' + idx}> | ||
<span dangerouslySetInnerHTML={{ __html: line }} /> | ||
<span dangerouslySetInnerHTML={{ __html: linkify(line) }} /> | ||
<br /> | ||
</span> | ||
)) | ||
}, [lines, record.id]) | ||
}, [lines, record.id, linkify]) | ||
|
||
const handleExpandClick = useCallback(() => { | ||
setExpanded(!expanded) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this log still needed? If it was just for debugging during development, I suggest to clean it up and prevent collecting clutter in the console panel 🧹