forked from Github/frigate
Improve stats (#10911)
* Add overview stats for overall detection and skipped fps * Fix intel memory stats * Fix iOS image long pressing * Cleanup
This commit is contained in:
46
web/src/hooks/use-contextmenu.ts
Normal file
46
web/src/hooks/use-contextmenu.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
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.preventDefault();
|
||||
callback();
|
||||
};
|
||||
elem.addEventListener("contextmenu", context);
|
||||
|
||||
return () => {
|
||||
elem.removeEventListener("contextmenu", context);
|
||||
};
|
||||
}
|
||||
}, [callback, ref]);
|
||||
}
|
||||
Reference in New Issue
Block a user