navidrome/ui/src/audioplayer/PlayerToolbar.js

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

35 lines
1023 B
JavaScript
Raw Normal View History

import React, { useCallback } from 'react'
2020-08-25 01:38:29 +02:00
import { useLocation } from 'react-router-dom'
import { useGetOne } from 'react-admin'
import { GlobalHotKeys } from 'react-hotkeys'
import { LoveButton, useToggleLove } from '../common'
2021-02-04 00:29:33 +01:00
import { keyMap } from '../hotkeys'
2020-08-25 01:38:29 +02:00
const Placeholder = () => <LoveButton disabled={true} resource={'song'} />
2020-08-25 01:38:29 +02:00
const Toolbar = ({ id }) => {
const location = useLocation()
const resource = location.pathname.startsWith('/song') ? 'song' : 'albumSong'
const { data, loading } = useGetOne(resource, id)
const [toggleLove, toggling] = useToggleLove(resource, data)
2020-08-25 01:38:29 +02:00
const handlers = {
TOGGLE_LOVE: useCallback(() => toggleLove(), [toggleLove]),
}
2020-08-25 01:38:29 +02:00
return (
<>
<GlobalHotKeys keyMap={keyMap} handlers={handlers} allowChanges />
<LoveButton
record={data}
resource={resource}
disabled={loading || toggling}
/>
</>
)
2020-08-25 01:38:29 +02:00
}
2020-10-02 23:26:20 +02:00
const PlayerToolbar = ({ id }) => (id ? <Toolbar id={id} /> : <Placeholder />)
2020-08-25 01:38:29 +02:00
export default PlayerToolbar