mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-10-04 11:15:55 +02:00
* Add note * Sort by event id * Fix reprocess causing shift * Move event group to separate comp * Handle selecting events * implement event selection * Implement selected handler * handle right click * Toggle ctrl + a * Stop propogation * Fix
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { MutableRefObject, useEffect } from "react";
|
|
import { isIOS } from "react-device-detect";
|
|
|
|
export default function useContextMenu(
|
|
ref: MutableRefObject<HTMLDivElement | null>,
|
|
callback: () => void,
|
|
) {
|
|
useEffect(() => {
|
|
if (!ref.current) {
|
|
return;
|
|
}
|
|
|
|
const elem = ref.current;
|
|
|
|
if (isIOS) {
|
|
let timeoutId: NodeJS.Timeout;
|
|
const touchStart = () => {
|
|
timeoutId = setTimeout(() => {
|
|
callback();
|
|
}, 610);
|
|
};
|
|
const touchClear = () => {
|
|
clearTimeout(timeoutId);
|
|
};
|
|
elem.addEventListener("touchstart", touchStart);
|
|
elem.addEventListener("touchmove", touchClear);
|
|
elem.addEventListener("touchend", touchClear);
|
|
|
|
return () => {
|
|
elem.removeEventListener("touchstart", touchStart);
|
|
elem.removeEventListener("touchmove", touchClear);
|
|
elem.removeEventListener("touchend", touchClear);
|
|
};
|
|
} else {
|
|
const context = (e: MouseEvent) => {
|
|
e.stopPropagation();
|
|
e.preventDefault();
|
|
callback();
|
|
};
|
|
elem.addEventListener("contextmenu", context);
|
|
|
|
return () => {
|
|
elem.removeEventListener("contextmenu", context);
|
|
};
|
|
}
|
|
}, [callback, ref]);
|
|
}
|