Make album genres clickable

This commit is contained in:
Deluan 2021-07-27 13:22:35 -04:00
parent e68b22ea5d
commit c0fc36da63

View file

@ -7,6 +7,7 @@ import {
makeStyles, makeStyles,
Typography, Typography,
useMediaQuery, useMediaQuery,
withWidth,
} from '@material-ui/core' } from '@material-ui/core'
import { import {
useRecordContext, useRecordContext,
@ -14,6 +15,7 @@ import {
ArrayField, ArrayField,
SingleFieldList, SingleFieldList,
ChipField, ChipField,
Link,
} from 'react-admin' } from 'react-admin'
import clsx from 'clsx' import clsx from 'clsx'
import Lightbox from 'react-image-lightbox' import Lightbox from 'react-image-lightbox'
@ -26,6 +28,7 @@ import {
SizeField, SizeField,
LoveButton, LoveButton,
RatingField, RatingField,
useAlbumsPerPage,
} from '../common' } from '../common'
import config from '../config' import config from '../config'
import { intersperse } from '../utils' import { intersperse } from '../utils'
@ -140,12 +143,35 @@ const AlbumComment = ({ record }) => {
) )
} }
export const useGetHandleGenreClick = (width) => {
const [perPage] = useAlbumsPerPage(width)
return (id) => {
return `/album?filter={"genre_id":"${id}"}&order=ASC&sort=name&perPage=${perPage}`
}
}
const GenreChipField = withWidth()(({ width, ...rest }) => {
const record = useRecordContext(rest)
const genreLink = useGetHandleGenreClick(width)
return (
<Link to={genreLink(record.id)} onClick={(e) => e.stopPropagation()}>
<ChipField
source="name"
// Workaround to force ChipField to be clickable
onClick={() => {}}
/>
</Link>
)
})
const GenreList = () => { const GenreList = () => {
const classes = useStyles() const classes = useStyles()
return ( return (
<ArrayField className={classes.genreList} source={'genres'}> <ArrayField className={classes.genreList} source={'genres'}>
<SingleFieldList linkType={false}> <SingleFieldList linkType={false}>
<ChipField source="name" /> <GenreChipField />
</SingleFieldList> </SingleFieldList>
</ArrayField> </ArrayField>
) )