diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 168fbcb..e02941a 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -6,7 +6,7 @@ import { GetAudioProgress, } from './generated/media_set'; -import { useState, useEffect, useRef } from 'react'; +import { useState, useEffect, useRef, useMemo } from 'react'; import { VideoPreview } from './VideoPreview'; import { Overview, CanvasLogicalWidth } from './Overview'; import { Waveform } from './Waveform'; @@ -192,6 +192,24 @@ function App(): JSX.Element { const offsetPixels = Math.floor(thumbnailWidth / 2); + // Avoid re-rendering this component during playback. Needs to be memoized + // before the mediaSet null check below. + const controlBar = useMemo( + () => ( + { + audio.play(); + video.play(); + }} + onPause={() => { + video.pause(); + audio.pause(); + }} + /> + ), + [] + ); + if (mediaSet == null) { // TODO: improve return <>; @@ -201,17 +219,7 @@ function App(): JSX.Element { <>
- { - audio.play(); - video.play(); - }} - onPause={() => { - video.pause(); - audio.pause(); - }} - /> - + {controlBar} = ({ return ( <>
- + {useMemo( + () => ( + + ), + [peaks, mediaSet] + )} = ({ return ( <>
- + {useMemo( + () => ( + + ), + [peaks, mediaSet] + )}