import React from 'react' import { GridList, GridListTile, Typography, GridListTileBar, useMediaQuery, } from '@material-ui/core' import { makeStyles } from '@material-ui/core/styles' import withWidth from '@material-ui/core/withWidth' import { Link } from 'react-router-dom' import { linkToRecord, useListContext, Loading } from 'react-admin' import { withContentRect } from 'react-measure' import { useDrag } from 'react-dnd' import subsonic from '../subsonic' import { AlbumContextMenu, PlayButton, ArtistLinkField } from '../common' import { DraggableTypes } from '../consts' import clsx from 'clsx' import { AlbumDatesField } from './AlbumDatesField.jsx' const useStyles = makeStyles( (theme) => ({ root: { margin: '20px', display: 'grid', }, tileBar: { transition: 'all 150ms ease-out', opacity: 0, textAlign: 'left', marginBottom: '3px', background: 'linear-gradient(to top, rgba(0,0,0,0.7) 0%,rgba(0,0,0,0.4) 70%,rgba(0,0,0,0) 100%)', }, tileBarMobile: { textAlign: 'left', marginBottom: '3px', background: 'linear-gradient(to top, rgba(0,0,0,0.7) 0%,rgba(0,0,0,0.4) 70%,rgba(0,0,0,0) 100%)', }, albumArtistName: { whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', textAlign: 'left', fontSize: '1em', }, albumName: { fontSize: '14px', color: theme.palette.type === 'dark' ? '#eee' : 'black', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis', }, missingAlbum: { opacity: 0.3, }, albumVersion: { fontSize: '12px', color: theme.palette.type === 'dark' ? '#c5c5c5' : '#696969', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis', }, albumSubtitle: { fontSize: '12px', color: theme.palette.type === 'dark' ? '#c5c5c5' : '#696969', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis', }, link: { position: 'relative', display: 'block', textDecoration: 'none', '&:hover $tileBar': { opacity: 1, }, }, albumLink: { position: 'relative', display: 'block', textDecoration: 'none', }, albumContainer: {}, albumPlayButton: { color: 'white' }, }), { name: 'NDAlbumGridView' }, ) const useCoverStyles = makeStyles({ cover: { display: 'inline-block', width: '100%', objectFit: 'contain', height: (props) => props.height, transition: 'opacity 0.3s ease-in-out', }, coverLoading: { opacity: 0.5, }, }) const getColsForWidth = (width) => { if (width === 'xs') return 2 if (width === 'sm') return 3 if (width === 'md') return 4 if (width === 'lg') return 6 return 9 } const Cover = withContentRect('bounds')(({ record, measureRef, contentRect, }) => { // Force height to be the same as the width determined by the GridList // noinspection JSSuspiciousNameCombination const classes = useCoverStyles({ height: contentRect.bounds.width }) const [imageLoading, setImageLoading] = React.useState(true) const [imageError, setImageError] = React.useState(false) const [, dragAlbumRef] = useDrag( () => ({ type: DraggableTypes.ALBUM, item: { albumIds: [record.id] }, options: { dropEffect: 'copy' }, }), [record], ) // Reset image state when record changes React.useEffect(() => { setImageLoading(true) setImageError(false) }, [record.id]) const handleImageLoad = React.useCallback(() => { setImageLoading(false) setImageError(false) }, []) const handleImageError = React.useCallback(() => { setImageLoading(false) setImageError(true) }, []) return (