8877b1695a
* add internet radio support * Add dynamic sidebar icon to Radios * Fix typos * Make URL suffix consistent * Fix typo * address feedback * Don't need to preload when playing Internet Radios * Reorder migration, or else it won't be applied * Make Radio list view responsive Also added filter by name, removed RadioActions and RadioContextMenu, and added a default radio icon, in case of favicon is not available. * Simplify StreamField usage * fix button, hide progress on mobile * use js styles over index.css Co-authored-by: Deluan <deluan@navidrome.org>
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
import { Button, makeStyles } from '@material-ui/core'
|
|
import PropTypes from 'prop-types'
|
|
import React, { useCallback } from 'react'
|
|
import { useRecordContext } from 'react-admin'
|
|
import { useDispatch } from 'react-redux'
|
|
import { setTrack } from '../actions'
|
|
import { songFromRadio } from './helper'
|
|
import PlayArrowIcon from '@material-ui/icons/PlayArrow'
|
|
|
|
const useStyles = makeStyles((theme) => ({
|
|
button: {
|
|
padding: '5px 0px',
|
|
textTransform: 'none',
|
|
marginRight: theme.spacing(1.5),
|
|
},
|
|
}))
|
|
|
|
export const StreamField = ({ hideUrl, ...rest }) => {
|
|
const record = useRecordContext(rest)
|
|
const dispatch = useDispatch()
|
|
const classes = useStyles()
|
|
|
|
const playTrack = useCallback(
|
|
async (evt) => {
|
|
evt.stopPropagation()
|
|
evt.preventDefault()
|
|
dispatch(setTrack(await songFromRadio(record)))
|
|
},
|
|
[dispatch, record]
|
|
)
|
|
|
|
return (
|
|
<Button className={classes.button} onClick={playTrack}>
|
|
<PlayArrowIcon />
|
|
{!hideUrl && record.streamUrl}
|
|
</Button>
|
|
)
|
|
}
|
|
|
|
StreamField.propTypes = {
|
|
label: PropTypes.string,
|
|
record: PropTypes.object,
|
|
source: PropTypes.string.isRequired,
|
|
hideUrl: PropTypes.bool,
|
|
}
|
|
|
|
StreamField.defaultProps = {
|
|
addLabel: true,
|
|
hideUrl: false,
|
|
}
|