feat: refactor long-press functionality in AllPrivateChatsSidebar and AllSharedChatsSidebar to utilize custom hook for improved code reusability and maintainability

This commit is contained in:
Anish Sarkar 2026-03-07 04:44:24 +05:30
parent 2ea67c1764
commit 37e1995546
3 changed files with 41 additions and 49 deletions

View file

@ -1,4 +1,4 @@
import { useCallback, useRef } from "react";
import { useCallback, useEffect, useRef } from "react";
const LONG_PRESS_DELAY = 500;
@ -21,6 +21,14 @@ export function useLongPress(onLongPress: () => void, delay = LONG_PRESS_DELAY)
}
}, []);
useEffect(() => {
return () => {
if (timerRef.current) {
clearTimeout(timerRef.current);
}
};
}, []);
const handlers = {
onTouchStart: start,
onTouchEnd: cancel,