swapped over context menu and quick items to completly functional components

This commit is contained in:
subnub
2024-06-22 04:32:54 -04:00
parent 4cccd43677
commit 45bcd5a7d6
7 changed files with 508 additions and 461 deletions
+39 -4
View File
@@ -1,12 +1,12 @@
import { useState } from "react";
import { useRef, useState } from "react";
export const useContextMenu = () => {
const [contextData, setContextData] = useState({
selected: false,
X: 0,
Y: 0,
lastTouched: 0,
});
const lastTouched = useRef(0);
const onContextMenu = (e: React.MouseEvent<HTMLDivElement>) => {
if (e) e.stopPropagation();
@@ -25,9 +25,44 @@ export const useContextMenu = () => {
selected: false,
X: 0,
Y: 0,
lastTouched: 0,
});
};
return { ...contextData, onContextMenu, closeContextMenu };
const onTouchStart = () => {
lastTouched.current = new Date().getTime();
};
const onTouchMove = () => {
lastTouched.current = 0;
};
const onTouchEnd = () => {
if (lastTouched.current === 0) {
return;
}
const date = new Date();
const difference = date.getTime() - lastTouched.current;
if (difference > 500) {
setContextData({
...contextData,
selected: true,
});
}
};
const clickStopPropagation = (e: React.MouseEvent<HTMLDivElement>) => {
e.stopPropagation();
};
return {
...contextData,
onContextMenu,
closeContextMenu,
onTouchStart,
onTouchMove,
onTouchEnd,
clickStopPropagation,
};
};