514aceb785
* ui: add save queue to playlist * fix(ui): improve toolbar layout Signed-off-by: Deluan <deluan@navidrome.org> * fix(ui): add loading state to save queue dialog Signed-off-by: Deluan <deluan@navidrome.org> * fix(ui): refresh playlist after saving queue Signed-off-by: Deluan <deluan@navidrome.org> * fix lint Signed-off-by: Deluan <deluan@navidrome.org> * remove duplication in PlayerToolbar and add tests Signed-off-by: Deluan <deluan@navidrome.org> * fix(i18n): update save queue text for clarity in English and Portuguese Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
65 lines
1.4 KiB
React
65 lines
1.4 KiB
React
import { useCallback, useMemo, useState } from 'react'
|
|
import { Typography, Collapse } from '@material-ui/core'
|
|
import { makeStyles } from '@material-ui/core/styles'
|
|
import AnchorMe from './Linkify'
|
|
import clsx from 'clsx'
|
|
|
|
const useStyles = makeStyles(
|
|
(theme) => ({
|
|
commentBlock: {
|
|
display: 'inline-block',
|
|
marginTop: '1em',
|
|
float: 'left',
|
|
wordBreak: 'break-word',
|
|
},
|
|
pointerCursor: {
|
|
cursor: 'pointer',
|
|
},
|
|
}),
|
|
{
|
|
name: 'NDCollapsibleComment',
|
|
},
|
|
)
|
|
|
|
export const CollapsibleComment = ({ record }) => {
|
|
const classes = useStyles()
|
|
const [expanded, setExpanded] = useState(false)
|
|
|
|
const lines = useMemo(
|
|
() => record.comment?.split('\n') || [],
|
|
[record.comment],
|
|
)
|
|
const formatted = useMemo(() => {
|
|
return lines.map((line, idx) => (
|
|
<span key={record.id + '-comment-' + idx}>
|
|
<AnchorMe text={line} />
|
|
<br />
|
|
</span>
|
|
))
|
|
}, [lines, record.id])
|
|
|
|
const handleExpandClick = useCallback(() => {
|
|
setExpanded(!expanded)
|
|
}, [expanded, setExpanded])
|
|
|
|
if (lines.length === 0) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<Collapse
|
|
collapsedHeight={'2em'}
|
|
in={expanded}
|
|
timeout={'auto'}
|
|
className={clsx(
|
|
classes.commentBlock,
|
|
lines.length > 1 && classes.pointerCursor,
|
|
)}
|
|
>
|
|
<Typography variant={'h6'} onClick={handleExpandClick}>
|
|
{formatted}
|
|
</Typography>
|
|
</Collapse>
|
|
)
|
|
}
|