Wrap comment text. Fixes #637
This commit is contained in:
parent
90c407b7f6
commit
ab856e3dd1
|
@ -1,27 +1,23 @@
|
||||||
import React, { useMemo } from 'react'
|
import React, { useMemo, useCallback } from 'react'
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
CardContent,
|
CardContent,
|
||||||
CardMedia,
|
CardMedia,
|
||||||
Typography,
|
|
||||||
Collapse,
|
Collapse,
|
||||||
makeStyles,
|
makeStyles,
|
||||||
IconButton,
|
Typography,
|
||||||
useMediaQuery,
|
useMediaQuery,
|
||||||
} from '@material-ui/core'
|
} from '@material-ui/core'
|
||||||
import classnames from 'classnames'
|
|
||||||
import { useTranslate } from 'react-admin'
|
import { useTranslate } from 'react-admin'
|
||||||
import Lightbox from 'react-image-lightbox'
|
import Lightbox from 'react-image-lightbox'
|
||||||
import 'react-image-lightbox/style.css'
|
import 'react-image-lightbox/style.css'
|
||||||
import ExpandMoreIcon from '@material-ui/icons/ExpandMore'
|
|
||||||
import subsonic from '../subsonic'
|
import subsonic from '../subsonic'
|
||||||
import {
|
import {
|
||||||
DurationField,
|
|
||||||
StarButton,
|
|
||||||
SizeField,
|
|
||||||
ArtistLinkField,
|
ArtistLinkField,
|
||||||
|
DurationField,
|
||||||
formatRange,
|
formatRange,
|
||||||
MultiLineTextField,
|
SizeField,
|
||||||
|
StarButton,
|
||||||
} from '../common'
|
} from '../common'
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
|
@ -73,79 +69,45 @@ const useStyles = makeStyles((theme) => ({
|
||||||
top: theme.spacing(-0.2),
|
top: theme.spacing(-0.2),
|
||||||
left: theme.spacing(0.5),
|
left: theme.spacing(0.5),
|
||||||
},
|
},
|
||||||
comment: {
|
commentBlock: {
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
marginTop: '1em',
|
|
||||||
display: 'inline-block',
|
display: 'inline-block',
|
||||||
[theme.breakpoints.down('xs')]: {
|
marginTop: '1em',
|
||||||
width: '10em',
|
|
||||||
},
|
|
||||||
[theme.breakpoints.up('sm')]: {
|
|
||||||
width: '10em',
|
|
||||||
},
|
|
||||||
[theme.breakpoints.up('lg')]: {
|
|
||||||
width: '10em',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
commentFirstLine: {
|
|
||||||
float: 'left',
|
float: 'left',
|
||||||
marginRight: '5px',
|
|
||||||
whiteSpace: 'nowrap',
|
|
||||||
overflow: 'hidden',
|
|
||||||
textOverflow: 'ellipsis',
|
|
||||||
},
|
|
||||||
expand: {
|
|
||||||
marginTop: '-5px',
|
|
||||||
transform: 'rotate(0deg)',
|
|
||||||
marginLeft: 'auto',
|
|
||||||
transition: theme.transitions.create('transform', {
|
|
||||||
duration: theme.transitions.duration.shortest,
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
expandOpen: {
|
|
||||||
transform: 'rotate(180deg)',
|
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
const AlbumComment = ({ classes, record, commentNumLines }) => {
|
const AlbumComment = ({ record }) => {
|
||||||
|
const classes = useStyles()
|
||||||
const [expanded, setExpanded] = React.useState(false)
|
const [expanded, setExpanded] = React.useState(false)
|
||||||
|
|
||||||
const handleExpandClick = React.useCallback(() => {
|
const formatted = useMemo(() => {
|
||||||
commentNumLines > 1 && setExpanded(!expanded)
|
return record.comment.split('\n').map((line) => (
|
||||||
}, [expanded, setExpanded, commentNumLines])
|
<>
|
||||||
|
{line}
|
||||||
|
<br />
|
||||||
|
</>
|
||||||
|
))
|
||||||
|
}, [record.comment])
|
||||||
|
|
||||||
|
const handleExpandClick = useCallback(() => {
|
||||||
|
setExpanded(!expanded)
|
||||||
|
}, [expanded, setExpanded])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.comment}>
|
<Collapse
|
||||||
<div onClick={handleExpandClick}>
|
collapsedHeight={'1.5em'}
|
||||||
<MultiLineTextField
|
in={expanded}
|
||||||
record={record}
|
timeout={'auto'}
|
||||||
source={'comment'}
|
className={classes.commentBlock}
|
||||||
maxLines={1}
|
|
||||||
className={classes.commentFirstLine}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
{commentNumLines > 1 && (
|
|
||||||
<IconButton
|
|
||||||
size={'small'}
|
|
||||||
className={classnames(classes.expand, {
|
|
||||||
[classes.expandOpen]: expanded,
|
|
||||||
})}
|
|
||||||
onClick={handleExpandClick}
|
|
||||||
aria-expanded={expanded}
|
|
||||||
aria-label="show more"
|
|
||||||
>
|
>
|
||||||
<ExpandMoreIcon />
|
<Typography
|
||||||
</IconButton>
|
variant={'body1'}
|
||||||
)}
|
className={classes.commentText}
|
||||||
<Collapse in={expanded} timeout="auto" unmountOnExit>
|
onClick={handleExpandClick}
|
||||||
<MultiLineTextField
|
>
|
||||||
record={record}
|
{formatted}
|
||||||
source={'comment'}
|
</Typography>
|
||||||
firstLine={1}
|
|
||||||
className={classes.commentFirstLine}
|
|
||||||
/>
|
|
||||||
</Collapse>
|
</Collapse>
|
||||||
</div>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,11 +117,6 @@ const AlbumDetails = ({ record }) => {
|
||||||
const [isLightboxOpen, setLightboxOpen] = React.useState(false)
|
const [isLightboxOpen, setLightboxOpen] = React.useState(false)
|
||||||
const translate = useTranslate()
|
const translate = useTranslate()
|
||||||
|
|
||||||
const commentNumLines = useMemo(
|
|
||||||
() => record.comment && record.comment.split('\n').length,
|
|
||||||
[record]
|
|
||||||
)
|
|
||||||
|
|
||||||
const genreYear = (record) => {
|
const genreYear = (record) => {
|
||||||
let genreDateLine = []
|
let genreDateLine = []
|
||||||
if (record.genre) {
|
if (record.genre) {
|
||||||
|
@ -228,23 +185,11 @@ const AlbumDetails = ({ record }) => {
|
||||||
{' · '}
|
{' · '}
|
||||||
<SizeField record={record} source="size" />
|
<SizeField record={record} source="size" />
|
||||||
</Typography>
|
</Typography>
|
||||||
{isDesktop && record['comment'] && (
|
{isDesktop && record['comment'] && <AlbumComment record={record} />}
|
||||||
<AlbumComment
|
|
||||||
classes={classes}
|
|
||||||
record={record}
|
|
||||||
commentNumLines={commentNumLines}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{!isDesktop && record['comment'] && (
|
{!isDesktop && record['comment'] && <AlbumComment record={record} />}
|
||||||
<AlbumComment
|
|
||||||
classes={classes}
|
|
||||||
record={record}
|
|
||||||
commentNumLines={commentNumLines}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{isLightboxOpen && (
|
{isLightboxOpen && (
|
||||||
<Lightbox
|
<Lightbox
|
||||||
imagePadding={50}
|
imagePadding={50}
|
||||||
|
|
Loading…
Reference in New Issue