Remove useless logic in MessageAudio
`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.
This commit is contained in:
parent
a3054ac0dc
commit
3eaa47ec72
1 changed files with 4 additions and 15 deletions
|
@ -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)
|
||||
);
|
||||
|
@ -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 () => {
|
||||
|
@ -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.
|
||||
|
|
Loading…
Add table
Reference in a new issue