Handle mouseUp event outside of Overview component

This commit is contained in:
Rob Watson 2021-11-23 14:06:50 +01:00
parent 4580915c3c
commit 33e6814fce
2 changed files with 13 additions and 3 deletions

View File

@ -158,8 +158,8 @@ function App(): JSX.Element {
height={80}
position={position}
selection={viewport}
onSelectionStart={(x1: number) => {
console.log('onSelectionStart', x1);
onSelectionStart={() => {
// empty
}}
onSelectionChange={handleOverviewSelectionChange}
/>

View File

@ -46,6 +46,17 @@ export const Overview: React.FC<Props> = ({
// effects
// handle global mouse up.
// Currently this adds and removes the global event listener every time the
// component is rerendered (which is often when dragging or redrawing). It
// works but probably better to optimize this for performance reasons.
useEffect(() => {
window.addEventListener('mouseup', handleMouseUp);
return () => {
window.removeEventListener('mouseup', handleMouseUp);
};
}, [mode, newSelection]);
// load peaks on mediaset change
useEffect(() => {
(async function () {
@ -244,7 +255,6 @@ export const Overview: React.FC<Props> = ({
style={hudCanvasStyles}
onMouseDown={handleMouseDown}
onMouseMove={handleMouseMove}
onMouseUp={handleMouseUp}
></canvas>
</div>
</>