quintodrome/ui/src/audioplayer/PlayerToolbar.js
Himanshu maurya 52812fa48b
Added quality info (#918)
* added quality info

* fixed formatting

* implemented various suggestions

* npm run prettier

* applied suggestions

* npm run prettier

* corrected lossless formats and other suggestions

* moved losslessformats into consts.js

* added some test

* typo while resolving conflicts

* fetch

* removed a bug causing component (as suggested)

* Update PlayerToolbar.js

* implemented suggestions

* added few more tests

* npm run prettier

* added size

* updated qualityInfo

* implemented suggestions

* added test for when no record is recieved

* Update QualityInfo.js
2021-04-06 21:30:17 -04:00

39 lines
1.2 KiB
JavaScript

import React, { useCallback } from 'react'
import { useLocation } from 'react-router-dom'
import { useGetOne } from 'react-admin'
import { GlobalHotKeys } from 'react-hotkeys'
import { LoveButton, useToggleLove } from '../common'
import { keyMap } from '../hotkeys'
import { QualityInfo } from '../common/QualityInfo'
import config from '../config'
const Placeholder = () =>
config.enableFavourites && <LoveButton disabled={true} resource={'song'} />
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)
const handlers = {
TOGGLE_LOVE: useCallback(() => toggleLove(), [toggleLove]),
}
return (
<>
{data && <QualityInfo record={data} sortable={false} />}
<GlobalHotKeys keyMap={keyMap} handlers={handlers} allowChanges />
{config.enableFavourites && (
<LoveButton
record={data}
resource={resource}
disabled={loading || toggling}
/>
)}
</>
)
}
const PlayerToolbar = ({ id }) => (id ? <Toolbar id={id} /> : <Placeholder />)
export default PlayerToolbar