2021-10-15 17:02:11 -08:00
|
|
|
import React from 'react'
|
|
|
|
|
import { useTranslate } from 'react-admin'
|
2021-10-21 06:30:53 -08:00
|
|
|
import { IconButton, Tooltip, Link } from '@material-ui/core'
|
2021-10-15 17:02:11 -08:00
|
|
|
|
|
|
|
|
import { ImLastfm2 } from 'react-icons/im'
|
|
|
|
|
import MusicBrainz from '../icons/MusicBrainz'
|
2026-02-04 13:34:26 -09:00
|
|
|
import { intersperse, isLastFmURL } from '../utils'
|
2022-12-30 13:15:14 -09:00
|
|
|
import config from '../config'
|
2025-05-26 14:21:55 -08:00
|
|
|
import { makeStyles } from '@material-ui/core/styles'
|
|
|
|
|
|
|
|
|
|
const useStyles = makeStyles({
|
|
|
|
|
linkBar: {
|
|
|
|
|
minHeight: '1.875em',
|
|
|
|
|
},
|
|
|
|
|
})
|
2021-10-15 17:02:11 -08:00
|
|
|
|
|
|
|
|
const ArtistExternalLinks = ({ artistInfo, record }) => {
|
2025-05-26 14:21:55 -08:00
|
|
|
const classes = useStyles()
|
2021-10-15 17:02:11 -08:00
|
|
|
const translate = useTranslate()
|
|
|
|
|
let linkButtons = []
|
|
|
|
|
const lastFMlink = artistInfo?.biography?.match(
|
2023-12-18 10:56:03 -09:00
|
|
|
/<a\s+(?:[^>]*?\s+)?href=(["'])(.*?)\1/,
|
2021-10-15 17:02:11 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const addLink = (url, title, icon) => {
|
|
|
|
|
const translatedTitle = translate(title)
|
|
|
|
|
const link = (
|
|
|
|
|
<Link href={url} target="_blank" rel="noopener noreferrer">
|
|
|
|
|
<Tooltip title={translatedTitle}>
|
|
|
|
|
<IconButton size={'small'} aria-label={translatedTitle}>
|
|
|
|
|
{icon}
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</Link>
|
|
|
|
|
)
|
|
|
|
|
const id = linkButtons.length
|
|
|
|
|
linkButtons.push(<span key={`link-${record.id}-${id}`}>{link}</span>)
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-30 13:15:14 -09:00
|
|
|
if (config.lastFMEnabled) {
|
2026-02-04 13:34:26 -09:00
|
|
|
if (lastFMlink && isLastFmURL(lastFMlink[2])) {
|
2023-11-16 15:07:52 -09:00
|
|
|
addLink(
|
|
|
|
|
lastFMlink[2],
|
|
|
|
|
'message.openIn.lastfm',
|
2023-12-18 10:56:03 -09:00
|
|
|
<ImLastfm2 className="lastfm-icon" />,
|
2023-11-16 15:07:52 -09:00
|
|
|
)
|
2026-02-04 13:34:26 -09:00
|
|
|
} else if (isLastFmURL(artistInfo?.lastFmUrl)) {
|
2023-11-16 15:07:52 -09:00
|
|
|
addLink(
|
|
|
|
|
artistInfo?.lastFmUrl,
|
|
|
|
|
'message.openIn.lastfm',
|
2023-12-18 10:56:03 -09:00
|
|
|
<ImLastfm2 className="lastfm-icon" />,
|
2023-11-16 15:07:52 -09:00
|
|
|
)
|
|
|
|
|
}
|
2022-12-30 13:15:14 -09:00
|
|
|
}
|
|
|
|
|
|
2021-10-21 06:30:53 -08:00
|
|
|
artistInfo?.musicBrainzId &&
|
2022-09-30 09:33:35 -08:00
|
|
|
addLink(
|
2023-11-16 15:07:52 -09:00
|
|
|
`https://musicbrainz.org/artist/${artistInfo.musicBrainzId}`,
|
2022-09-30 09:33:35 -08:00
|
|
|
'message.openIn.musicbrainz',
|
2023-12-18 10:56:03 -09:00
|
|
|
<MusicBrainz className="musicbrainz-icon" />,
|
2022-09-30 09:33:35 -08:00
|
|
|
)
|
2021-10-15 17:02:11 -08:00
|
|
|
|
2025-05-26 14:21:55 -08:00
|
|
|
return <div className={classes.linkBar}>{intersperse(linkButtons, ' ')}</div>
|
2021-10-15 17:02:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ArtistExternalLinks
|