quintodrome/ui/src/common/ArtistLinkField.js

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

36 lines
903 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
export 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
}
export const ArtistLinkField = withWidth()(({ 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>
)
})
2020-05-14 16:42:21 -08:00
ArtistLinkField.propTypes = {
record: PropTypes.object,
2020-05-14 16:42:21 -08:00
className: PropTypes.string,
}
ArtistLinkField.defaultProps = {
addLabel: true,
}