Add "clean up timer if necessary" utility

This commit is contained in:
Evan Hahn 2022-02-25 12:37:15 -06:00 committed by GitHub
parent c2a65306e2
commit 052a8e65e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 150 additions and 137 deletions

View file

@ -6,6 +6,7 @@ import type { ActiveCallType } from '../types/Calling';
import { CallMode, GroupCallConnectionState } from '../types/Calling';
import type { ConversationType } from '../state/ducks/conversations';
import type { LocalizerType } from '../types/Util';
import { clearTimeoutIfNecessary } from '../util/clearTimeoutIfNecessary';
import { CallingToast, DEFAULT_LIFETIME } from './CallingToast';
type PropsType = {
@ -126,9 +127,7 @@ export const CallingToastManager: React.FC<PropsType> = props => {
useEffect(() => {
if (toast) {
if (toast.type === 'dismissable') {
if (timeoutRef && timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
clearTimeoutIfNecessary(timeoutRef.current);
timeoutRef.current = setTimeout(dismissToast, DEFAULT_LIFETIME);
}
@ -136,9 +135,7 @@ export const CallingToastManager: React.FC<PropsType> = props => {
}
return () => {
if (timeoutRef && timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
clearTimeoutIfNecessary(timeoutRef.current);
};
}, [dismissToast, setToastMessage, timeoutRef, toast]);