Skip to content

Commit

Permalink
Prevent subtitle list re-render during audio recording
Browse files Browse the repository at this point in the history
- Re-rendering can cause skips/delays in audio recording
- Instead of disabling the copy button in UI, just prevent it from doing
  anything during audio recording
  • Loading branch information
killergerbah committed Jan 28, 2024
1 parent cda3acd commit 9149abf
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions common/app/components/SubtitlePlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ interface SubtitleRowProps extends TableRowProps {
disabled: boolean;
subtitle: DisplaySubtitleModel;
showCopyButton: boolean;
copyButtonEnabled: boolean;
subtitleRef: RefObject<HTMLTableRowElement>;
onClickSubtitle: (index: number) => void;
onCopySubtitle: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>, index: number) => void;
Expand All @@ -218,7 +217,6 @@ const SubtitleRow = React.memo(function SubtitleRow({
compressed,
disabled,
subtitle,
copyButtonEnabled,
showCopyButton,
}: SubtitleRowProps) {
const classes = useSubtitleRowStyles();
Expand Down Expand Up @@ -278,10 +276,7 @@ const SubtitleRow = React.memo(function SubtitleRow({
{selectionState !== undefined && <TableCell className={className}>{content}</TableCell>}
{showCopyButton && (
<TableCell className={classes.copyButton}>
<IconButton
disabled={!copyButtonEnabled || selectionState !== undefined}
onClick={(e) => onCopySubtitle(e, index)}
>
<IconButton disabled={selectionState !== undefined} onClick={(e) => onCopySubtitle(e, index)}>
<NoteAddIcon fontSize={compressed ? 'small' : 'medium'} />
</IconButton>
</TableCell>
Expand Down Expand Up @@ -904,13 +899,15 @@ export default function SubtitlePlayer({
settingsRef.current = settings;
const onCopyRef = useRef(onCopy);
onCopyRef.current = onCopy;
const copyButtonEnabledRef = useRef(copyButtonEnabled);
copyButtonEnabledRef.current = copyButtonEnabled;

const handleCopy = useCallback(
(e: React.MouseEvent<HTMLButtonElement, MouseEvent>, index: number) => {
e.preventDefault();
e.stopPropagation();

if (!subtitles) {
if (!subtitles || !copyButtonEnabledRef.current) {
return;
}

Expand Down Expand Up @@ -1083,7 +1080,6 @@ export default function SubtitlePlayer({
highlighted={highlighted}
selectionState={selectionState}
showCopyButton={showCopyButton}
copyButtonEnabled={copyButtonEnabled}
disabled={disabledSubtitleTracks[s.track]}
subtitle={subtitles[index]}
subtitleRef={subtitleRefs[index]}
Expand Down

0 comments on commit 9149abf

Please sign in to comment.