import React, { useMemo, useCallback } from 'react' import { Card, CardContent, CardMedia, Collapse, makeStyles, Typography, useMediaQuery, } from '@material-ui/core' import { useTranslate } from 'react-admin' import Lightbox from 'react-image-lightbox' import 'react-image-lightbox/style.css' import subsonic from '../subsonic' import { ArtistLinkField, DurationField, formatRange, SizeField, StarButton, } from '../common' const useStyles = makeStyles((theme) => ({ root: { [theme.breakpoints.down('xs')]: { padding: '0.7em', minWidth: '24em', }, [theme.breakpoints.up('sm')]: { padding: '1em', minWidth: '32em', }, }, cardContents: { display: 'flex', }, details: { display: 'flex', flexDirection: 'column', }, content: { flex: '2 0 auto', }, coverParent: { [theme.breakpoints.down('xs')]: { height: '8em', width: '8em', minWidth: '8em', }, [theme.breakpoints.up('sm')]: { height: '10em', width: '10em', minWidth: '10em', }, [theme.breakpoints.up('lg')]: { height: '15em', width: '15em', minWidth: '15em', }, }, cover: { objectFit: 'contain', cursor: 'pointer', display: 'block', width: '100%', height: '100%', }, starButton: { top: theme.spacing(-0.2), left: theme.spacing(0.5), }, commentBlock: { display: 'inline-block', marginTop: '1em', float: 'left', }, })) const AlbumComment = ({ record }) => { const classes = useStyles() const [expanded, setExpanded] = React.useState(false) const formatted = useMemo(() => { return record.comment.split('\n').map((line, idx) => (
)) }, [record.comment, record.id]) const handleExpandClick = useCallback(() => { setExpanded(!expanded) }, [expanded, setExpanded]) return ( {formatted} ) } const AlbumDetails = ({ record }) => { 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.url( 'getCoverArt', record.coverArtId || 'not_found', { size: 300 } ) const fullImageUrl = subsonic.url( 'getCoverArt', record.coverArtId || 'not_found' ) const handleOpenLightbox = React.useCallback(() => setLightboxOpen(true), []) const handleCloseLightbox = React.useCallback( () => setLightboxOpen(false), [] ) return (
{record.name} {genreYear(record)} {record.songCount}{' '} {translate('resources.song.name', { smart_count: record.songCount, })} {' · '} {' '} {' · '} {isDesktop && record['comment'] && }
{!isDesktop && record['comment'] && } {isLightboxOpen && ( )}
) } export default AlbumDetails