navidrome/ui/src/common/ArtistLinkField.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-05-15 02:42:21 +02:00
import React from 'react'
import PropTypes from 'prop-types'
import { Link } from 'react-admin'
import { withWidth } from '@material-ui/core'
import { useAlbumsPerPage } from './index'
import config from '../config'
2020-05-15 02:42:21 +02:00
export const useGetHandleArtistClick = (width) => {
const [perPage] = useAlbumsPerPage(width)
return (id) => {
return config.devShowArtistPage && id !== config.variousArtistsId
? `/artist/${id}/show`
: `/album?filter={"artist_id":"${id}"}&order=ASC&sort=max_year&displayedFilters={"compilation":true}&perPage=${perPage}`
}
2020-05-15 02:42:21 +02:00
}
2021-11-06 01:25:12 +01:00
export const ArtistLinkField = withWidth()(
({ record, className, width, source }) => {
const artistLink = useGetHandleArtistClick(width)
2021-11-06 01:25:12 +01:00
const id = record[source + 'Id']
return (
<>
{id ? (
<Link
to={artistLink(id)}
onClick={(e) => e.stopPropagation()}
className={className}
>
{record[source]}
</Link>
) : (
record[source]
)}
</>
2021-11-06 01:25:12 +01:00
)
}
)
2020-05-15 02:42:21 +02:00
ArtistLinkField.propTypes = {
record: PropTypes.object,
2020-05-15 02:42:21 +02:00
className: PropTypes.string,
2021-11-06 01:25:12 +01:00
source: PropTypes.string,
2020-05-15 02:42:21 +02:00
}
ArtistLinkField.defaultProps = {
addLabel: true,
2021-11-06 01:25:12 +01:00
source: 'albumArtist',
2020-05-15 02:42:21 +02:00
}