quintodrome/ui/src/audioplayer/PlayerToolbar.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
1,023 B
JavaScript
Raw Normal View History

import React, { useCallback } from 'react'
2020-08-24 15:38:29 -08:00
import { useLocation } from 'react-router-dom'
import { useGetOne } from 'react-admin'
import { GlobalHotKeys } from 'react-hotkeys'
import { StarButton, useToggleStar } from '../common'
2021-02-03 14:29:33 -09:00
import { keyMap } from '../hotkeys'
2020-08-24 15:38:29 -08:00
const Placeholder = () => <StarButton disabled={true} resource={'song'} />
2020-08-24 15:38:29 -08:00
const Toolbar = ({ id }) => {
const location = useLocation()
const resource = location.pathname.startsWith('/song') ? 'song' : 'albumSong'
const { data, loading } = useGetOne(resource, id)
const [toggleStar, toggling] = useToggleStar(resource, data)
2020-08-24 15:38:29 -08:00
const handlers = {
TOGGLE_STAR: useCallback(() => toggleStar(), [toggleStar]),
}
2020-08-24 15:38:29 -08:00
return (
<>
<GlobalHotKeys keyMap={keyMap} handlers={handlers} allowChanges />
<StarButton
record={data}
resource={resource}
disabled={loading || toggling}
/>
</>
)
2020-08-24 15:38:29 -08:00
}
2020-10-02 13:26:20 -08:00
const PlayerToolbar = ({ id }) => (id ? <Toolbar id={id} /> : <Placeholder />)
2020-08-24 15:38:29 -08:00
export default PlayerToolbar