navidrome/ui/src/audioplayer/PlayerToolbar.js

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

43 lines
1.4 KiB
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'
import { ThemeProvider } from '@material-ui/styles'
import { createMuiTheme } from '@material-ui/core/styles'
import useCurrentTheme from '../themes/useCurrentTheme'
import config from '../config'
2020-08-25 01:38:29 +02:00
const Placeholder = () =>
config.enableFavourites && <LoveButton disabled={true} resource={'song'} />
2020-08-25 01:38:29 +02:00
const Toolbar = ({ id }) => {
const location = useLocation()
const theme = useCurrentTheme()
2020-08-25 01:38:29 +02:00
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 (
<ThemeProvider theme={createMuiTheme(theme)}>
<GlobalHotKeys keyMap={keyMap} handlers={handlers} allowChanges />
{config.enableFavourites && (
<LoveButton
record={data}
resource={resource}
disabled={loading || toggling}
/>
)}
</ThemeProvider>
)
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