Add Genres as "Chips" in Album details and Song details
This commit is contained in:
@@ -8,7 +8,13 @@ import {
|
||||
Typography,
|
||||
useMediaQuery,
|
||||
} from '@material-ui/core'
|
||||
import { useTranslate } from 'react-admin'
|
||||
import {
|
||||
useRecordContext,
|
||||
useTranslate,
|
||||
ArrayField,
|
||||
SingleFieldList,
|
||||
ChipField,
|
||||
} from 'react-admin'
|
||||
import clsx from 'clsx'
|
||||
import Lightbox from 'react-image-lightbox'
|
||||
import 'react-image-lightbox/style.css'
|
||||
@@ -22,6 +28,7 @@ import {
|
||||
RatingField,
|
||||
} from '../common'
|
||||
import config from '../config'
|
||||
import { intersperse } from '../utils'
|
||||
|
||||
const useStyles = makeStyles(
|
||||
(theme) => ({
|
||||
@@ -85,6 +92,9 @@ const useStyles = makeStyles(
|
||||
recordName: {},
|
||||
recordArtist: {},
|
||||
recordMeta: {},
|
||||
genreList: {
|
||||
marginTop: theme.spacing(1),
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: 'NDAlbumDetails',
|
||||
@@ -126,23 +136,49 @@ const AlbumComment = ({ record }) => {
|
||||
)
|
||||
}
|
||||
|
||||
const AlbumDetails = ({ record }) => {
|
||||
const GenreList = () => {
|
||||
const classes = useStyles()
|
||||
return (
|
||||
<ArrayField className={classes.genreList} source={'genres'}>
|
||||
<SingleFieldList linkType={false}>
|
||||
<ChipField source="name" />
|
||||
</SingleFieldList>
|
||||
</ArrayField>
|
||||
)
|
||||
}
|
||||
|
||||
const Details = (props) => {
|
||||
const isXsmall = useMediaQuery((theme) => theme.breakpoints.down('xs'))
|
||||
const translate = useTranslate()
|
||||
const record = useRecordContext(props)
|
||||
let details = []
|
||||
const addDetail = (obj) => {
|
||||
const id = details.length
|
||||
details.push(<span key={`detail-${record.id}-${id}`}>{obj}</span>)
|
||||
}
|
||||
|
||||
const year = formatRange(record, 'year')
|
||||
year && addDetail(<>{year}</>)
|
||||
addDetail(
|
||||
<>
|
||||
{record.songCount +
|
||||
' ' +
|
||||
translate('resources.song.name', {
|
||||
smart_count: record.songCount,
|
||||
})}
|
||||
</>
|
||||
)
|
||||
!isXsmall && addDetail(<DurationField source={'duration'} />)
|
||||
!isXsmall && addDetail(<SizeField source="size" />)
|
||||
|
||||
return <>{intersperse(details, ' · ')}</>
|
||||
}
|
||||
|
||||
const AlbumDetails = (props) => {
|
||||
const record = useRecordContext(props)
|
||||
const isDesktop = useMediaQuery((theme) => theme.breakpoints.up('lg'))
|
||||
const classes = useStyles()
|
||||
const [isLightboxOpen, setLightboxOpen] = React.useState(false)
|
||||
const translate = useTranslate()
|
||||
|
||||
const genreYear = (record) => {
|
||||
let genreDateLine = []
|
||||
if (record.genre) {
|
||||
genreDateLine.push(record.genre)
|
||||
}
|
||||
const year = formatRange(record, 'year')
|
||||
if (year) {
|
||||
genreDateLine.push(year)
|
||||
}
|
||||
return genreDateLine.join(' · ')
|
||||
}
|
||||
|
||||
const imageUrl = subsonic.getCoverArtUrl(record, 300)
|
||||
const fullImageUrl = subsonic.getCoverArtUrl(record)
|
||||
@@ -188,16 +224,7 @@ const AlbumDetails = ({ record }) => {
|
||||
<ArtistLinkField record={record} />
|
||||
</Typography>
|
||||
<Typography component="p" className={classes.recordMeta}>
|
||||
{genreYear(record)}
|
||||
</Typography>
|
||||
<Typography component="p" className={classes.recordMeta}>
|
||||
{record.songCount}{' '}
|
||||
{translate('resources.song.name', {
|
||||
smart_count: record.songCount,
|
||||
})}
|
||||
{' · '} <DurationField record={record} source={'duration'} />{' '}
|
||||
{' · '}
|
||||
<SizeField record={record} source="size" />
|
||||
<Details />
|
||||
</Typography>
|
||||
{config.enableStarRating && (
|
||||
<div>
|
||||
@@ -208,6 +235,7 @@ const AlbumDetails = ({ record }) => {
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<GenreList />
|
||||
{isDesktop && record['comment'] && <AlbumComment record={record} />}
|
||||
</CardContent>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import React, { useMemo } from 'react'
|
||||
import Paper from '@material-ui/core/Paper'
|
||||
import Table from '@material-ui/core/Table'
|
||||
import TableBody from '@material-ui/core/TableBody'
|
||||
import inflection from 'inflection'
|
||||
@@ -7,12 +6,15 @@ import TableCell from '@material-ui/core/TableCell'
|
||||
import TableContainer from '@material-ui/core/TableContainer'
|
||||
import TableRow from '@material-ui/core/TableRow'
|
||||
import {
|
||||
ArrayField,
|
||||
BooleanField,
|
||||
ChipField,
|
||||
Datagrid,
|
||||
DateField,
|
||||
NumberField,
|
||||
Show,
|
||||
SingleFieldList,
|
||||
TextField,
|
||||
useRecordContext,
|
||||
useTranslate,
|
||||
} from 'react-admin'
|
||||
import { useMediaQuery } from '@material-ui/core'
|
||||
@@ -60,43 +62,50 @@ const useStyles = makeStyles({
|
||||
const AlbumDetails = (props) => {
|
||||
const classes = useStyles()
|
||||
const translate = useTranslate()
|
||||
const { record } = props
|
||||
const record = useRecordContext(props)
|
||||
const data = {
|
||||
albumArtist: <TextField record={record} source="albumArtist" />,
|
||||
genre: <TextField record={record} source="genre" />,
|
||||
compilation: <BooleanField record={record} source="compilation" />,
|
||||
updatedAt: <DateField record={record} source="updatedAt" showTime />,
|
||||
comment: <MultiLineTextField record={record} source="comment" />,
|
||||
}
|
||||
if (!record.comment) {
|
||||
delete data.comment
|
||||
albumArtist: <TextField source={'albumArtist'} />,
|
||||
genre: (
|
||||
<ArrayField source={'genres'}>
|
||||
<SingleFieldList linkType={false}>
|
||||
<ChipField source={'name'} />
|
||||
</SingleFieldList>
|
||||
</ArrayField>
|
||||
),
|
||||
compilation: <BooleanField source={'compilation'} />,
|
||||
updatedAt: <DateField source={'updatedAt'} showTime />,
|
||||
comment: <MultiLineTextField source={'comment'} />,
|
||||
}
|
||||
|
||||
const optionalFields = ['comment', 'genre']
|
||||
optionalFields.forEach((field) => {
|
||||
!record[field] && delete data[field]
|
||||
})
|
||||
|
||||
return (
|
||||
<Show {...props} title=" ">
|
||||
<TableContainer component={Paper}>
|
||||
<Table aria-label="album details" size="small">
|
||||
<TableBody>
|
||||
{Object.keys(data).map((key) => {
|
||||
return (
|
||||
<TableRow key={`${record.id}-${key}`}>
|
||||
<TableCell
|
||||
component="th"
|
||||
scope="row"
|
||||
className={classes.tableCell}
|
||||
>
|
||||
{translate(`resources.album.fields.${key}`, {
|
||||
_: inflection.humanize(inflection.underscore(key)),
|
||||
})}
|
||||
:
|
||||
</TableCell>
|
||||
<TableCell align="left">{data[key]}</TableCell>
|
||||
</TableRow>
|
||||
)
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
</Show>
|
||||
<TableContainer>
|
||||
<Table aria-label="album details" size="small">
|
||||
<TableBody>
|
||||
{Object.keys(data).map((key) => {
|
||||
return (
|
||||
<TableRow key={`${record.id}-${key}`}>
|
||||
<TableCell
|
||||
component="th"
|
||||
scope="row"
|
||||
className={classes.tableCell}
|
||||
>
|
||||
{translate(`resources.album.fields.${key}`, {
|
||||
_: inflection.humanize(inflection.underscore(key)),
|
||||
})}
|
||||
:
|
||||
</TableCell>
|
||||
<TableCell align="left">{data[key]}</TableCell>
|
||||
</TableRow>
|
||||
)
|
||||
})}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user