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
971 B
JavaScript
Raw Normal View History

import React, { useCallback } from 'react'
2020-08-24 15:38:29 -08:00
import { useGetOne } from 'react-admin'
import { GlobalHotKeys } from 'react-hotkeys'
import { LoveButton, useToggleLove } from '../common'
2021-02-03 14:29:33 -09:00
import { keyMap } from '../hotkeys'
import config from '../config'
2020-08-24 15:38:29 -08:00
const Placeholder = () =>
config.enableFavourites && <LoveButton disabled={true} resource={'song'} />
2020-08-24 15:38:29 -08:00
const Toolbar = ({ id }) => {
const { data, loading } = useGetOne('song', id)
const [toggleLove, toggling] = useToggleLove('song', data)
2020-08-24 15:38:29 -08:00
const handlers = {
TOGGLE_LOVE: useCallback(() => toggleLove(), [toggleLove]),
}
return (
<>
<GlobalHotKeys keyMap={keyMap} handlers={handlers} allowChanges />
{config.enableFavourites && (
<LoveButton
record={data}
resource={'song'}
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