2020-05-15 02:42:21 +02:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { Link } from 'react-admin'
|
2020-06-10 02:29:12 +02:00
|
|
|
import { withWidth } from '@material-ui/core'
|
2021-09-26 21:32:40 +02:00
|
|
|
import { useAlbumsPerPage } from './index'
|
|
|
|
import config from '../config'
|
2020-05-15 02:42:21 +02:00
|
|
|
|
2020-11-11 01:27:28 +01:00
|
|
|
export const useGetHandleArtistClick = (width) => {
|
2020-06-10 02:29:12 +02:00
|
|
|
const [perPage] = useAlbumsPerPage(width)
|
|
|
|
return (id) => {
|
2021-09-27 17:52:23 +02:00
|
|
|
return config.devShowArtistPage && id !== config.variousArtistsId
|
2021-09-26 21:32:40 +02:00
|
|
|
? `/artist/${id}/show`
|
2021-11-18 03:47:14 +01:00
|
|
|
: `/album?filter={"artist_id":"${id}"}&order=ASC&sort=max_year&displayedFilters={"compilation":true}&perPage=${perPage}`
|
2020-06-10 02:29:12 +02:00
|
|
|
}
|
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-09-26 21:32:40 +02:00
|
|
|
|
2021-11-06 01:25:12 +01:00
|
|
|
const id = record[source + 'Id']
|
|
|
|
return (
|
2021-11-18 00:47:54 +01:00
|
|
|
<>
|
|
|
|
{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 = {
|
2020-06-12 23:02:04 +02:00
|
|
|
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
|
|
|
}
|