2021-12-04 04:34:17 +00:00
|
|
|
import React from 'react';
|
2022-02-10 19:00:45 +00:00
|
|
|
import { PlayState } from './AppState';
|
2022-01-14 11:54:54 +00:00
|
|
|
import {
|
|
|
|
CloudDownloadIcon,
|
|
|
|
FastForwardIcon,
|
|
|
|
PauseIcon,
|
|
|
|
PlayIcon,
|
|
|
|
RewindIcon,
|
|
|
|
ZoomInIcon,
|
|
|
|
ZoomOutIcon,
|
|
|
|
} from '@heroicons/react/solid';
|
2021-12-04 04:34:17 +00:00
|
|
|
|
2021-10-08 14:38:35 +00:00
|
|
|
interface Props {
|
2022-01-14 11:54:54 +00:00
|
|
|
playState: PlayState;
|
2022-01-17 17:58:19 +00:00
|
|
|
zoomInEnabled: boolean;
|
|
|
|
zoomOutEnabled: boolean;
|
2022-01-14 11:54:54 +00:00
|
|
|
onTogglePlay: () => void;
|
2021-12-29 15:38:25 +00:00
|
|
|
onClip: () => void;
|
2022-01-07 18:51:29 +00:00
|
|
|
onZoomIn: () => void;
|
|
|
|
onZoomOut: () => void;
|
2022-01-17 17:58:13 +00:00
|
|
|
downloadClipEnabled: boolean;
|
2021-10-08 14:38:35 +00:00
|
|
|
}
|
|
|
|
|
2021-12-04 04:34:17 +00:00
|
|
|
const ControlBar: React.FC<Props> = React.memo((props: Props) => {
|
2022-01-14 11:54:54 +00:00
|
|
|
const buttonStyle =
|
2022-01-17 17:58:19 +00:00
|
|
|
'bg-gray-600 hover:bg-gray-500 text-white font-bold py-2 px-4 rounded';
|
|
|
|
|
|
|
|
const disabledButtonStyle =
|
|
|
|
'bg-gray-700 text-white font-bold py-2 px-4 rounded cursor-auto';
|
2022-01-14 11:54:54 +00:00
|
|
|
|
2022-01-17 17:58:13 +00:00
|
|
|
const downloadButtonStyle = props.downloadClipEnabled
|
2022-01-17 17:58:19 +00:00
|
|
|
? 'bg-green-600 hover:bg-green-600 text-white font-bold py-2 px-4 rounded absolute right-0'
|
|
|
|
: 'bg-gray-600 hover:cursor-not-allowed text-gray-500 font-bold py-2 px-4 rounded absolute right-0';
|
2022-01-14 11:54:54 +00:00
|
|
|
|
2022-01-17 17:58:13 +00:00
|
|
|
const iconStyle = 'inline h-7 w-7 text-white-500';
|
2022-01-14 11:54:54 +00:00
|
|
|
|
|
|
|
const playPauseComponent =
|
|
|
|
props.playState == PlayState.Playing ? (
|
|
|
|
<PauseIcon className={iconStyle} />
|
|
|
|
) : (
|
|
|
|
<PlayIcon className={iconStyle} />
|
|
|
|
);
|
2021-10-08 14:38:35 +00:00
|
|
|
|
2022-01-17 17:58:13 +00:00
|
|
|
const handleClip = () => {
|
|
|
|
if (props.downloadClipEnabled) {
|
|
|
|
props.onClip();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-14 19:11:14 +00:00
|
|
|
// Detect if the space bar has been used to trigger this event, and ignore
|
|
|
|
// it if so. This conflicts with the player interface.
|
|
|
|
const filterMouseEvent = (evt: React.MouseEvent, cb: () => void) => {
|
|
|
|
if (evt.detail == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cb();
|
|
|
|
};
|
|
|
|
|
2021-10-08 14:38:35 +00:00
|
|
|
return (
|
|
|
|
<>
|
2022-01-14 11:54:54 +00:00
|
|
|
<div className="relative grow-0 w-full py-2 space-x-2">
|
|
|
|
<button className={buttonStyle}>
|
|
|
|
<RewindIcon className={iconStyle} />
|
|
|
|
</button>
|
2022-01-14 19:11:14 +00:00
|
|
|
<button
|
|
|
|
className={buttonStyle}
|
|
|
|
onClick={(evt) => filterMouseEvent(evt, props.onTogglePlay)}
|
|
|
|
>
|
2022-01-14 11:54:54 +00:00
|
|
|
{playPauseComponent}
|
2021-10-08 14:38:35 +00:00
|
|
|
</button>
|
2022-01-14 11:54:54 +00:00
|
|
|
<button className={buttonStyle}>
|
|
|
|
<FastForwardIcon className={iconStyle} />
|
2021-10-08 14:38:35 +00:00
|
|
|
</button>
|
2022-01-14 19:11:14 +00:00
|
|
|
<button
|
2022-01-17 17:58:19 +00:00
|
|
|
className={props.zoomInEnabled ? buttonStyle : disabledButtonStyle}
|
2022-01-14 19:11:14 +00:00
|
|
|
onClick={(evt) => filterMouseEvent(evt, props.onZoomIn)}
|
|
|
|
>
|
2022-01-14 11:54:54 +00:00
|
|
|
<ZoomInIcon className={iconStyle} />
|
2021-12-29 15:38:25 +00:00
|
|
|
</button>
|
2022-01-14 19:11:14 +00:00
|
|
|
<button
|
2022-01-17 17:58:19 +00:00
|
|
|
className={props.zoomOutEnabled ? buttonStyle : disabledButtonStyle}
|
2022-01-14 19:11:14 +00:00
|
|
|
onClick={(evt) => filterMouseEvent(evt, props.onZoomOut)}
|
|
|
|
>
|
2022-01-14 11:54:54 +00:00
|
|
|
<ZoomOutIcon className={iconStyle} />
|
2022-01-07 18:51:29 +00:00
|
|
|
</button>
|
2022-01-14 19:11:14 +00:00
|
|
|
<button
|
2022-01-17 17:58:13 +00:00
|
|
|
className={downloadButtonStyle}
|
|
|
|
onClick={(evt) => filterMouseEvent(evt, handleClip)}
|
2022-01-14 19:11:14 +00:00
|
|
|
>
|
2022-01-14 11:54:54 +00:00
|
|
|
<CloudDownloadIcon className={`${iconStyle} mr-2`} />
|
2022-01-17 17:58:13 +00:00
|
|
|
Download clip as MP3
|
2022-01-07 18:51:29 +00:00
|
|
|
</button>
|
2021-10-08 14:38:35 +00:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
2021-12-04 04:34:17 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
ControlBar.displayName = 'ControlBar';
|
|
|
|
export { ControlBar };
|