diff --git a/src/hooks/useEnsureMessage.ts b/src/hooks/useEnsureMessage.ts index bb2f03a39..1c889390b 100644 --- a/src/hooks/useEnsureMessage.ts +++ b/src/hooks/useEnsureMessage.ts @@ -1,29 +1,19 @@ -import { useEffect, useMemo } from '../lib/teact/teact'; +import { useEffect } from '../lib/teact/teact'; import { getActions } from '../global'; import type { ApiMessage } from '../api/types'; -import { throttle } from '../util/schedulers'; - -const useEnsureMessage = ( +export default function useEnsureMessage( chatId: string, messageId?: number, message?: ApiMessage, replyOriginForId?: number, -) => { +) { const { loadMessage } = getActions(); - const loadMessageThrottled = useMemo(() => { - const throttled = throttle(loadMessage, 500, true); - return () => { - throttled({ chatId, messageId: messageId!, replyOriginForId: replyOriginForId! }); - }; - }, [loadMessage, chatId, messageId, replyOriginForId]); useEffect(() => { if (messageId && !message) { - loadMessageThrottled(); + loadMessage({ chatId, messageId: messageId!, replyOriginForId: replyOriginForId! }); } - }); -}; - -export default useEnsureMessage; + }, [chatId, message, messageId, replyOriginForId]); +} diff --git a/src/hooks/useFastClick.ts b/src/hooks/useFastClick.ts index 418a98a81..87b8bb591 100644 --- a/src/hooks/useFastClick.ts +++ b/src/hooks/useFastClick.ts @@ -1,20 +1,21 @@ import type React from '../lib/teact/teact'; import { IS_TOUCH_ENV, MouseButton } from '../util/windowEnvironment'; +import useLastCallback from './useLastCallback'; type EventArg = React.MouseEvent; type EventHandler = (e: EventArg) => void; export function useFastClick(callback?: EventHandler) { - const wrapperHandler = callback ? (e: EventArg) => { + const handler = useLastCallback((e: EventArg) => { if (e.type === 'mousedown' && e.button !== MouseButton.Main) { return; } - callback(e); - } : undefined; + callback!(e); + }); return IS_TOUCH_ENV - ? { handleClick: wrapperHandler } - : { handleMouseDown: wrapperHandler }; + ? { handleClick: callback ? handler : undefined } + : { handleMouseDown: callback ? handler : undefined }; } diff --git a/src/lib/teact/teact.ts b/src/lib/teact/teact.ts index e3ce4c7c5..2f7bdb42c 100644 --- a/src/lib/teact/teact.ts +++ b/src/lib/teact/teact.ts @@ -313,7 +313,7 @@ document.addEventListener('dblclick', () => { Object .values(DEBUG_components) .map(({ avgRenderTime, ...state }) => { - return { ...state, ...(avgRenderTime && { avgRenderTime: Number(avgRenderTime.toFixed(2)) }) }; + return { ...state, ...(avgRenderTime !== undefined && { avgRenderTime: Number(avgRenderTime.toFixed(2)) }) }; }), 'renders', 'desc',