quintodrome/ui/src/common/ArtistLinkField.js

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

40 lines
957 B
JavaScript
Raw Normal View History

2020-05-14 16:42:21 -08:00
import React from 'react'
import PropTypes from 'prop-types'
import { Link } from 'react-admin'
import { useAlbumsPerPage } from './index'
import { withWidth } from '@material-ui/core'
2020-05-14 16:42:21 -08:00
const useGetHandleArtistClick = (width) => {
const [perPage] = useAlbumsPerPage(width)
return (id) => {
return `/album?filter={"artist_id":"${id}"}&order=ASC&sort=maxYear&displayedFilters={"compilation":true}&perPage=${perPage}`
}
2020-05-14 16:42:21 -08:00
}
const ArtistLinkField = ({ record, className, width }) => {
const artistLink = useGetHandleArtistClick(width)
2020-05-14 16:42:21 -08:00
return (
<Link
to={artistLink(record.albumArtistId)}
onClick={(e) => e.stopPropagation()}
className={className}
>
{record.albumArtist}
</Link>
)
}
ArtistLinkField.propTypes = {
record: PropTypes.object,
2020-05-14 16:42:21 -08:00
className: PropTypes.string,
}
ArtistLinkField.defaultProps = {
addLabel: true,
}
export { useGetHandleArtistClick }
2020-05-14 16:42:21 -08:00
export default withWidth()(ArtistLinkField)