Add StarButton to player
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
|||||||
import themes from '../themes'
|
import themes from '../themes'
|
||||||
import { makeStyles } from '@material-ui/core/styles'
|
import { makeStyles } from '@material-ui/core/styles'
|
||||||
import config from '../config'
|
import config from '../config'
|
||||||
|
import PlayerToolbar from './PlayerToolbar'
|
||||||
import Hotkeys from 'react-hot-keys'
|
import Hotkeys from 'react-hot-keys'
|
||||||
|
|
||||||
const useStyle = makeStyles((theme) => ({
|
const useStyle = makeStyles((theme) => ({
|
||||||
@@ -98,6 +99,7 @@ const Player = () => {
|
|||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const queue = useSelector((state) => state.queue)
|
const queue = useSelector((state) => state.queue)
|
||||||
const { authenticated } = useAuthState()
|
const { authenticated } = useAuthState()
|
||||||
|
const current = queue.current || {}
|
||||||
|
|
||||||
const options = useMemo(() => {
|
const options = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
@@ -106,9 +108,10 @@ const Player = () => {
|
|||||||
autoPlay: queue.clear || queue.playIndex === 0,
|
autoPlay: queue.clear || queue.playIndex === 0,
|
||||||
playIndex: queue.playIndex,
|
playIndex: queue.playIndex,
|
||||||
audioLists: queue.queue.map((item) => item),
|
audioLists: queue.queue.map((item) => item),
|
||||||
|
extendsContent: <PlayerToolbar id={current.trackId} />,
|
||||||
defaultVolume: queue.volume,
|
defaultVolume: queue.volume,
|
||||||
}
|
}
|
||||||
}, [queue.clear, queue.queue, queue.volume, queue.playIndex, defaultOptions])
|
}, [queue.clear, queue.queue, queue.volume, queue.playIndex, current, defaultOptions])
|
||||||
|
|
||||||
const OnAudioListsChange = useCallback(
|
const OnAudioListsChange = useCallback(
|
||||||
(currentPlayIndex, audioLists) => {
|
(currentPlayIndex, audioLists) => {
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import { useLocation } from 'react-router-dom'
|
||||||
|
import { useGetOne } from 'react-admin'
|
||||||
|
import IconButton from '@material-ui/core/IconButton'
|
||||||
|
import StarBorderIcon from '@material-ui/icons/StarBorder'
|
||||||
|
import { StarButton } from '../common'
|
||||||
|
|
||||||
|
const Placeholder = () => (
|
||||||
|
<IconButton>
|
||||||
|
<StarBorderIcon disabled={true} />
|
||||||
|
</IconButton>
|
||||||
|
)
|
||||||
|
|
||||||
|
const Toolbar = ({ id }) => {
|
||||||
|
const location = useLocation()
|
||||||
|
const resource = location.pathname.startsWith('/song') ? 'song' : 'albumSong'
|
||||||
|
const { data, loading } = useGetOne(resource, id)
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
|
return <Placeholder />
|
||||||
|
}
|
||||||
|
|
||||||
|
return <StarButton record={data} resource={resource} />
|
||||||
|
}
|
||||||
|
|
||||||
|
const PlayerToolbar = ({ id }) => (
|
||||||
|
<>{id ? <Toolbar id={id} /> : <Placeholder />} </>
|
||||||
|
)
|
||||||
|
|
||||||
|
export default PlayerToolbar
|
||||||
@@ -71,6 +71,7 @@ StarButton.defaultProps = {
|
|||||||
record: {},
|
record: {},
|
||||||
visible: true,
|
visible: true,
|
||||||
size: 'small',
|
size: 'small',
|
||||||
|
color: 'inherit',
|
||||||
}
|
}
|
||||||
|
|
||||||
export default StarButton
|
export default StarButton
|
||||||
|
|||||||
Reference in New Issue
Block a user