diff --git a/ui/src/album/AlbumSongList.js b/ui/src/album/AlbumSongList.js index 1f2f5be1..f965b45d 100644 --- a/ui/src/album/AlbumSongList.js +++ b/ui/src/album/AlbumSongList.js @@ -1,10 +1,12 @@ import React from 'react' -import { SimpleList, useGetList } from 'react-admin' -import { DurationField, PlayButton } from '../common' -import { addTrack } from '../player' +import { useGetList } from 'react-admin' +import { DurationField, PlayButton, SimpleList } from '../common' +import { addTrack, setTrack } from '../player' import AddIcon from '@material-ui/icons/Add' +import { useDispatch } from 'react-redux' const AlbumSongList = (props) => { + const dispatch = useDispatch() const { record } = props const { data, total, loading, error } = useGetList( 'song', @@ -39,7 +41,7 @@ const AlbumSongList = (props) => { r.albumArtist && r.artist !== r.albumArtist ? r.artist : '' } tertiaryText={(r) => } - linkType={false} + linkType={(id, basePath, record) => dispatch(setTrack(record))} /> ) } diff --git a/ui/src/common/PlayButton.js b/ui/src/common/PlayButton.js index 8a26d3a7..e3760cf2 100644 --- a/ui/src/common/PlayButton.js +++ b/ui/src/common/PlayButton.js @@ -17,7 +17,10 @@ const PlayButton = ({ return ( dispatch(action(record))} + onClick={(e) => { + e.stopPropagation() + dispatch(action(record)) + }} {...rest} size={'small'} > diff --git a/ui/src/common/SimpleList.js b/ui/src/common/SimpleList.js new file mode 100644 index 00000000..6b377128 --- /dev/null +++ b/ui/src/common/SimpleList.js @@ -0,0 +1,149 @@ +import React from 'react' +import PropTypes from 'prop-types' +import Avatar from '@material-ui/core/Avatar' +import List from '@material-ui/core/List' +import ListItem from '@material-ui/core/ListItem' +import ListItemAvatar from '@material-ui/core/ListItemAvatar' +import ListItemIcon from '@material-ui/core/ListItemIcon' +import ListItemSecondaryAction from '@material-ui/core/ListItemSecondaryAction' +import ListItemText from '@material-ui/core/ListItemText' +import { makeStyles } from '@material-ui/core/styles' +import { Link } from 'react-router-dom' +import { linkToRecord, sanitizeListRestProps } from 'ra-core' + +const useStyles = makeStyles( + { + link: { + textDecoration: 'none', + color: 'inherit' + }, + tertiary: { float: 'right', opacity: 0.541176 } + }, + { name: 'RaSimpleList' } +) + +const LinkOrNot = ({ + classes: classesOverride, + linkType, + basePath, + id, + record, + children +}) => { + const classes = useStyles({ classes: classesOverride }) + return linkType === 'edit' || linkType === true ? ( + + {children} + + ) : linkType === 'show' ? ( + + {children} + + ) : typeof linkType === 'function' ? ( + linkType(id, basePath, record)}>{children} + ) : ( + {children} + ) +} + +const SimpleList = ({ + basePath, + className, + classes: classesOverride, + data, + hasBulkActions, + ids, + loading, + leftAvatar, + leftIcon, + linkType, + onToggleItem, + primaryText, + rightAvatar, + rightIcon, + secondaryText, + selectedIds, + tertiaryText, + total, + ...rest +}) => { + const classes = useStyles({ classes: classesOverride }) + return ( + (loading || total > 0) && ( + + {ids.map((id) => ( + + + {leftIcon && ( + {leftIcon(data[id], id)} + )} + {leftAvatar && ( + + {leftAvatar(data[id], id)} + + )} + + {primaryText(data[id], id)} + {tertiaryText && ( + + {tertiaryText(data[id], id)} + + )} + + } + secondary={secondaryText && secondaryText(data[id], id)} + /> + {(rightAvatar || rightIcon) && ( + + {rightAvatar && {rightAvatar(data[id], id)}} + {rightIcon && ( + {rightIcon(data[id], id)} + )} + + )} + + + ))} + + ) + ) +} + +SimpleList.propTypes = { + basePath: PropTypes.string, + className: PropTypes.string, + classes: PropTypes.object, + data: PropTypes.object, + hasBulkActions: PropTypes.bool.isRequired, + ids: PropTypes.array, + leftAvatar: PropTypes.func, + leftIcon: PropTypes.func, + linkType: PropTypes.oneOfType([ + PropTypes.string, + PropTypes.bool, + PropTypes.func + ]).isRequired, + onToggleItem: PropTypes.func, + primaryText: PropTypes.func, + rightAvatar: PropTypes.func, + rightIcon: PropTypes.func, + secondaryText: PropTypes.func, + selectedIds: PropTypes.arrayOf(PropTypes.any).isRequired, + tertiaryText: PropTypes.func +} + +SimpleList.defaultProps = { + linkType: 'edit', + hasBulkActions: false, + selectedIds: [] +} + +export default SimpleList diff --git a/ui/src/common/index.js b/ui/src/common/index.js index b99e3b5a..3189a5fa 100644 --- a/ui/src/common/index.js +++ b/ui/src/common/index.js @@ -3,5 +3,13 @@ import DurationField from './DurationField' import BitrateField from './BitrateField' import Pagination from './Pagination' import PlayButton from './PlayButton' +import SimpleList from './SimpleList' -export { Title, DurationField, BitrateField, Pagination, PlayButton } +export { + Title, + DurationField, + BitrateField, + Pagination, + PlayButton, + SimpleList +} diff --git a/ui/src/song/SongList.js b/ui/src/song/SongList.js index 5be2cd1f..f18e3d35 100644 --- a/ui/src/song/SongList.js +++ b/ui/src/song/SongList.js @@ -10,13 +10,12 @@ import { Show, SimpleShowLayout, TextField, - TextInput, - SimpleList + TextInput } from 'react-admin' import { useMediaQuery } from '@material-ui/core' import { BitrateField, DurationField, Pagination, Title } from '../common' import AddToQueueButton from './AddToQueueButton' -import { PlayButton } from '../common' +import { PlayButton, SimpleList } from '../common' import { useDispatch } from 'react-redux' import { setTrack, addTrack } from '../player' import AddIcon from '@material-ui/icons/Add' @@ -82,7 +81,7 @@ const SongList = (props) => { tertiaryText={(record) => ( )} - linkType={false} + linkType={(id, basePath, record) => dispatch(setTrack(record))} /> ) : (