Skip to content

Commit

Permalink
Make album genres clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Jul 27, 2021
1 parent e68b22e commit c0fc36d
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion ui/src/album/AlbumDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import {
makeStyles,
Typography,
useMediaQuery,
withWidth,
} from '@material-ui/core'
import {
useRecordContext,
useTranslate,
ArrayField,
SingleFieldList,
ChipField,
Link,
} from 'react-admin'
import clsx from 'clsx'
import Lightbox from 'react-image-lightbox'
Expand All @@ -26,6 +28,7 @@ import {
SizeField,
LoveButton,
RatingField,
useAlbumsPerPage,
} from '../common'
import config from '../config'
import { intersperse } from '../utils'
Expand Down Expand Up @@ -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 classes = useStyles()
return (
<ArrayField className={classes.genreList} source={'genres'}>
<SingleFieldList linkType={false}>
<ChipField source="name" />
<GenreChipField />
</SingleFieldList>
</ArrayField>
)
Expand Down

0 comments on commit c0fc36d

Please sign in to comment.