Skip to content
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

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 24 additions & 2 deletions ui/src/album/AlbumDetails.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useMemo, useCallback } from 'react'

import {
Card,
CardContent,
Expand Down Expand Up @@ -101,6 +102,10 @@ const useStyles = makeStyles(
},
externalLinks: {
marginTop: theme.spacing(1.5),
color: theme.palette.text.primary,
'&:hover': {
color: theme.palette.primary.dark,
},
},
}),
{
Expand All @@ -112,15 +117,32 @@ const AlbumComment = ({ record }) => {
const classes = useStyles()
const [expanded, setExpanded] = React.useState(false)

const reqClassName = classes.externalLinks
console.log(reqClassName)

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 🧹

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>'

Choose a reason for hiding this comment

The 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 <Link> component without extra styles in this file. I would like to test this out, but at the moment I am not finished with setting up the linting stuff in my dev-environment.

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)
Expand Down