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} height={80}
position={position} position={position}
selection={viewport} selection={viewport}
onSelectionStart={(x1: number) => { onSelectionStart={() => {
console.log('onSelectionStart', x1); // empty
}} }}
onSelectionChange={handleOverviewSelectionChange} onSelectionChange={handleOverviewSelectionChange}
/> />

View File

@ -46,6 +46,17 @@ export const Overview: React.FC<Props> = ({
// effects // 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 // load peaks on mediaset change
useEffect(() => { useEffect(() => {
(async function () { (async function () {
@ -244,7 +255,6 @@ export const Overview: React.FC<Props> = ({
style={hudCanvasStyles} style={hudCanvasStyles}
onMouseDown={handleMouseDown} onMouseDown={handleMouseDown}
onMouseMove={handleMouseMove} onMouseMove={handleMouseMove}
onMouseUp={handleMouseUp}
></canvas> ></canvas>
</div> </div>
</> </>