2021-02-02 18:15:13 -09:00
|
|
|
import React, { useCallback } from 'react'
|
2020-08-24 15:38:29 -08:00
|
|
|
import { useLocation } from 'react-router-dom'
|
|
|
|
|
import { useGetOne } from 'react-admin'
|
2021-02-02 18:15:13 -09:00
|
|
|
import { GlobalHotKeys } from 'react-hotkeys'
|
2021-03-26 19:56:19 -08:00
|
|
|
import { LoveButton, useToggleLove } from '../common'
|
2021-02-03 14:29:33 -09:00
|
|
|
import { keyMap } from '../hotkeys'
|
2021-04-06 17:30:17 -08:00
|
|
|
import { QualityInfo } from '../common/QualityInfo'
|
2021-03-28 16:35:49 -08:00
|
|
|
import config from '../config'
|
2020-08-24 15:38:29 -08:00
|
|
|
|
2021-03-28 16:35:49 -08:00
|
|
|
const Placeholder = () =>
|
|
|
|
|
config.enableFavourites && <LoveButton 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)
|
2021-03-26 19:56:19 -08:00
|
|
|
const [toggleLove, toggling] = useToggleLove(resource, data)
|
2020-08-24 15:38:29 -08:00
|
|
|
|
2021-02-02 18:15:13 -09:00
|
|
|
const handlers = {
|
2021-03-26 19:56:19 -08:00
|
|
|
TOGGLE_LOVE: useCallback(() => toggleLove(), [toggleLove]),
|
2021-02-02 18:15:13 -09:00
|
|
|
}
|
2020-11-27 20:51:31 -09:00
|
|
|
return (
|
2021-03-30 18:21:24 -08:00
|
|
|
<>
|
2021-04-06 17:30:17 -08:00
|
|
|
{data && <QualityInfo record={data} sortable={false} />}
|
2021-02-02 18:15:13 -09:00
|
|
|
<GlobalHotKeys keyMap={keyMap} handlers={handlers} allowChanges />
|
2021-03-28 16:35:49 -08:00
|
|
|
{config.enableFavourites && (
|
|
|
|
|
<LoveButton
|
|
|
|
|
record={data}
|
|
|
|
|
resource={resource}
|
|
|
|
|
disabled={loading || toggling}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2021-03-30 18:21:24 -08:00
|
|
|
</>
|
2020-11-27 20:51:31 -09:00
|
|
|
)
|
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
|