Skip to content

Commit

Permalink
Remove useless logic in MessageAudio
Browse files Browse the repository at this point in the history
`isLoading` was initially used to avoid duplicate loads of the audio on
re-renders, but this has to be handled in GlobalAudioContext not in
MessageAudio.
  • Loading branch information
indutny-signal authored and josh-signal committed Mar 19, 2021
1 parent a3054ac commit 3eaa47e
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions ts/components/conversation/MessageAudio.tsx
Expand Up @@ -230,7 +230,6 @@ export const MessageAudio: React.FC<Props> = (props: Props) => {
// NOTE: Avoid division by zero
const [duration, setDuration] = useState(1e-23);

const [isLoading, setIsLoading] = useState(true);
const [peaks, setPeaks] = useState<ReadonlyArray<number>>(
new Array(PEAK_COUNT).fill(0)
);
Expand All @@ -248,10 +247,12 @@ export const MessageAudio: React.FC<Props> = (props: Props) => {
// This effect loads audio file and computes its RMS peak for dispalying the
// waveform.
useEffect(() => {
if (!isLoading || state !== State.Normal) {
if (state !== State.Normal) {
return noop;
}

window.log.info('MessageAudio: loading audio and computing waveform');

let canceled = false;

(async () => {
Expand All @@ -275,25 +276,13 @@ export const MessageAudio: React.FC<Props> = (props: Props) => {
setDuration(Math.max(newDuration, 1e-23));
} catch (err) {
window.log.error('MessageAudio: loadAudio error', err);
} finally {
if (!canceled) {
setIsLoading(false);
}
}
})();

return () => {
canceled = true;
};
}, [
attachment,
audioContext,
isLoading,
setDuration,
setPeaks,
state,
waveformCache,
]);
}, [attachment, audioContext, setDuration, setPeaks, state, waveformCache]);

// This effect attaches/detaches event listeners to the global <audio/>
// instance that we reuse from the GlobalAudioContext.
Expand Down

0 comments on commit 3eaa47e

Please sign in to comment.