From b864835f400145b196eb40f9c70b5a80c88d26d3 Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Wed, 17 Nov 2021 20:17:26 +0100 Subject: [PATCH] Overview: render viewport on first render --- frontend/src/App.tsx | 1 + frontend/src/Overview.tsx | 9 +++------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index b79d1e9..377fb35 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -150,6 +150,7 @@ function App(): JSX.Element { offsetPixels={offsetPixels} height={80} position={position} + selection={viewport} onSelectionStart={(x1: number) => { console.log('onSelectionStart', x1); }} diff --git a/frontend/src/Overview.tsx b/frontend/src/Overview.tsx index 15026f6..122fe86 100644 --- a/frontend/src/Overview.tsx +++ b/frontend/src/Overview.tsx @@ -12,6 +12,7 @@ interface Props { height: number; offsetPixels: number; position: number; + selection: Frames; onSelectionStart: (x1: number) => void; onSelectionChange: (selection: Frames) => void; } @@ -33,13 +34,13 @@ export const Overview: React.FC = ({ height, offsetPixels, position, + selection, onSelectionStart, onSelectionChange, }: Props) => { const hudCanvasRef = useRef(null); const [peaks, setPeaks] = useState>(from([])); const [mode, setMode] = useState(Mode.Normal); - const [selection, setSelection] = useState({ ...emptySelection }); const [newSelection, setNewSelection] = useState({ ...emptySelection }); const [dragStart, setDragStart] = useState(0); @@ -142,10 +143,6 @@ export const Overview: React.FC = ({ onSelectionStart(newSelection.start); }, [newSelection]); - useEffect(() => { - onSelectionChange({ ...selection }); - }, [selection]); - // handlers const handleMouseDown = (evt: MouseEvent) => { @@ -207,7 +204,7 @@ export const Overview: React.FC = ({ } setMode(Mode.Normal); - setSelection(newSelection); + onSelectionChange({ ...newSelection }); }; // render component