mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-09 11:52:35 +03:00
refactor: simplify PlayButton usage
This commit is contained in:
parent
a50735a94c
commit
8f0c07d29f
@ -1,4 +1,4 @@
|
|||||||
import React, { Fragment } from 'react'
|
import React from 'react'
|
||||||
import { Loading, useGetOne } from 'react-admin'
|
import { Loading, useGetOne } from 'react-admin'
|
||||||
import { Card, CardContent, CardMedia, Typography } from '@material-ui/core'
|
import { Card, CardContent, CardMedia, Typography } from '@material-ui/core'
|
||||||
import { subsonicUrl } from '../subsonic'
|
import { subsonicUrl } from '../subsonic'
|
||||||
|
@ -32,8 +32,8 @@ const AlbumSongList = (props) => {
|
|||||||
total={total}
|
total={total}
|
||||||
primaryText={(r) => (
|
primaryText={(r) => (
|
||||||
<>
|
<>
|
||||||
<PlayButton record={r} />
|
<PlayButton action={setTrack(r)} />
|
||||||
<PlayButton record={r} action={addTrack} icon={<AddIcon />} />
|
<PlayButton action={addTrack(r)} icon={<AddIcon />} />
|
||||||
{trackName(r)}
|
{trackName(r)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
@ -3,23 +3,17 @@ import PropTypes from 'prop-types'
|
|||||||
import PlayArrowIcon from '@material-ui/icons/PlayArrow'
|
import PlayArrowIcon from '@material-ui/icons/PlayArrow'
|
||||||
import { IconButton } from '@material-ui/core'
|
import { IconButton } from '@material-ui/core'
|
||||||
import { useDispatch } from 'react-redux'
|
import { useDispatch } from 'react-redux'
|
||||||
import { setTrack } from '../player'
|
|
||||||
|
|
||||||
const defaultIcon = <PlayArrowIcon fontSize="small" />
|
const defaultIcon = <PlayArrowIcon fontSize="small" />
|
||||||
|
|
||||||
const PlayButton = ({
|
const PlayButton = ({ icon = defaultIcon, action, ...rest }) => {
|
||||||
record,
|
|
||||||
icon = defaultIcon,
|
|
||||||
action = setTrack,
|
|
||||||
...rest
|
|
||||||
}) => {
|
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<IconButton
|
<IconButton
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
dispatch(action(record))
|
dispatch(action)
|
||||||
}}
|
}}
|
||||||
{...rest}
|
{...rest}
|
||||||
size={'small'}
|
size={'small'}
|
||||||
@ -30,8 +24,7 @@ const PlayButton = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
PlayButton.propTypes = {
|
PlayButton.propTypes = {
|
||||||
record: PropTypes.any,
|
|
||||||
icon: PropTypes.element,
|
icon: PropTypes.element,
|
||||||
action: PropTypes.func
|
action: PropTypes.object
|
||||||
}
|
}
|
||||||
export default PlayButton
|
export default PlayButton
|
||||||
|
@ -66,21 +66,15 @@ const SongList = (props) => {
|
|||||||
>
|
>
|
||||||
{isXsmall ? (
|
{isXsmall ? (
|
||||||
<SimpleList
|
<SimpleList
|
||||||
primaryText={(record) => (
|
primaryText={(r) => (
|
||||||
<>
|
<>
|
||||||
<PlayButton record={record} />
|
<PlayButton action={setTrack(r)} />
|
||||||
<PlayButton
|
<PlayButton action={addTrack(r)} icon={<AddIcon />} />
|
||||||
record={record}
|
{r.title}
|
||||||
action={addTrack}
|
|
||||||
icon={<AddIcon />}
|
|
||||||
/>
|
|
||||||
{record.title}
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
secondaryText={(record) => record.artist}
|
secondaryText={(r) => r.artist}
|
||||||
tertiaryText={(record) => (
|
tertiaryText={(r) => <DurationField record={r} source={'duration'} />}
|
||||||
<DurationField record={record} source={'duration'} />
|
|
||||||
)}
|
|
||||||
linkType={(id, basePath, record) => dispatch(setTrack(record))}
|
linkType={(id, basePath, record) => dispatch(setTrack(record))}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user