Restructure project to root layout

This commit is contained in:
beatz174-bit
2025-11-21 16:10:41 +10:00
parent e0e26a34ab
commit 3ffe9bbf99
51 changed files with 16 additions and 12 deletions
+44
View File
@@ -0,0 +1,44 @@
import { useCallback, useMemo, useRef } from 'react';
interface LongPressOptions {
delay?: number;
onLongPress: () => void;
onClick?: () => void;
}
export const useLongPress = ({ delay = 500, onLongPress, onClick }: LongPressOptions) => {
const timerRef = useRef<number>();
const handledRef = useRef(false);
const start = useCallback(() => {
handledRef.current = false;
timerRef.current = window.setTimeout(() => {
handledRef.current = true;
onLongPress();
}, delay);
}, [delay, onLongPress]);
const clear = useCallback(() => {
if (timerRef.current) {
clearTimeout(timerRef.current);
}
}, []);
const onRelease = useCallback(() => {
clear();
if (!handledRef.current && onClick) {
onClick();
}
}, [clear, onClick]);
return useMemo(
() => ({
onMouseDown: start,
onTouchStart: start,
onMouseUp: onRelease,
onMouseLeave: clear,
onTouchEnd: onRelease,
}),
[start, onRelease, clear],
);
};