quintodrome/ui/src/album/AlbumDetails.js

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

74 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-02-07 12:38:01 -09:00
import React from 'react'
import { Card, CardContent, CardMedia, Typography } from '@material-ui/core'
import { useTranslate } from 'react-admin'
2020-08-21 08:41:23 -08:00
import Lightbox from 'react-image-lightbox'
import 'react-image-lightbox/style.css'
import subsonic from '../subsonic'
import { DurationField, formatRange, StarButton, SizeField } from '../common'
2020-05-14 16:42:21 -08:00
import { ArtistLinkField } from '../common'
2020-10-22 20:49:24 -08:00
import { PlayButton } from '../common'
const AlbumDetails = ({ classes, record }) => {
2020-08-21 08:41:23 -08:00
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(' · ')
}
2020-08-21 08:41:23 -08:00
const imageUrl = subsonic.url('getCoverArt', record.coverArtId || 'not_found')
const handleOpenLightbox = React.useCallback(() => setLightboxOpen(true), [])
const handleCloseLightbox = React.useCallback(
() => setLightboxOpen(false),
[]
)
return (
<Card className={classes.container}>
<CardMedia
2020-08-21 08:41:23 -08:00
image={imageUrl}
className={classes.albumCover}
2020-08-21 08:41:23 -08:00
onClick={handleOpenLightbox}
>
<PlayButton record={record} className={classes.playButton} size={"large"} />
</CardMedia>
<CardContent className={classes.albumDetails}>
<Typography variant="h5" className={classes.albumTitle}>
{record.name}
</Typography>
<Typography component="h6">
<ArtistLinkField record={record} />
</Typography>
<Typography component="p">{genreYear(record)}</Typography>
<Typography component="p">
{record.songCount}{' '}
{translate('resources.song.name', { smart_count: record.songCount })}{' '}
· <DurationField record={record} source={'duration'} /> ·{' '}
<SizeField record={record} source="size" />
</Typography>
2020-08-22 19:41:25 -08:00
<StarButton record={record} resource={'album'} size={'large'} />
</CardContent>
2020-08-21 08:41:23 -08:00
{isLightboxOpen && (
<Lightbox
imagePadding={50}
animationDuration={200}
imageTitle={record.name}
mainSrc={imageUrl}
onCloseRequest={handleCloseLightbox}
/>
)}
</Card>
)
}
2020-02-07 11:04:45 -09:00
export default AlbumDetails