refactor: enhance event handling in DashboardCard, ZoneGroup, SelectionControls, and KeyPressListener components

This commit is contained in:
Jerald-Golden-B 2025-06-05 16:11:40 +05:30
parent 3575f2bf73
commit cb0e67129c
4 changed files with 13 additions and 11 deletions

View File

@ -187,7 +187,7 @@ const DashboardCard: React.FC<DashBoardCardProps> = ({
<div className="preview-container"> <div className="preview-container">
{thumbnail ? <img src={thumbnail} alt="" /> : <img src={img} alt="" />} {thumbnail ? <img src={thumbnail} alt="" /> : <img src={img} alt="" />}
</div> </div>
<div className="project-details-container"> <div className="project-details-container" onClick={(e) => { e.stopPropagation() }}>
<div className="project-details"> <div className="project-details">
{isRenaming ? ( {isRenaming ? (
<input <input

View File

@ -433,6 +433,7 @@ const ZoneGroup: React.FC = () => {
}; };
const onMouseMove = () => { const onMouseMove = () => {
if (!groupsRef.current) return;
if (isLeftMouseDown) { if (isLeftMouseDown) {
drag = true; drag = true;
} }

View File

@ -1,5 +1,5 @@
import * as THREE from "three"; import * as THREE from "three";
import { useEffect, useMemo, useRef, useState } from "react"; import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { SelectionBox } from "three/examples/jsm/interactive/SelectionBox"; import { SelectionBox } from "three/examples/jsm/interactive/SelectionBox";
import { SelectionHelper } from "./selectionHelper"; import { SelectionHelper } from "./selectionHelper";
import { useFrame, useThree } from "@react-three/fiber"; import { useFrame, useThree } from "@react-three/fiber";
@ -212,7 +212,7 @@ const SelectionControls: React.FC = () => {
} }
}); });
const selectAssets = () => { const selectAssets = useCallback(() => {
selectionBox.endPoint.set(pointer.x, pointer.y, 0); selectionBox.endPoint.set(pointer.x, pointer.y, 0);
if (controls) (controls as any).enabled = true; if (controls) (controls as any).enabled = true;
@ -241,7 +241,7 @@ const SelectionControls: React.FC = () => {
const selected = Array.from(updatedSelections); const selected = Array.from(updatedSelections);
setSelectedAssets(selected); setSelectedAssets(selected);
}; }, [selectionBox, pointer, controls, selectedAssets, setSelectedAssets]);
const clearSelection = () => { const clearSelection = () => {
selectionGroup.current.children = []; selectionGroup.current.children = [];
@ -280,11 +280,18 @@ const SelectionControls: React.FC = () => {
userId userId
}; };
socket.emit("v1:model-asset:delete", data); const response = socket.emit("v1:model-asset:delete", data);
useEventsStore.getState().removeEvent(selectedMesh.uuid); useEventsStore.getState().removeEvent(selectedMesh.uuid);
useProductStore.getState().deleteEvent(selectedMesh.uuid); useProductStore.getState().deleteEvent(selectedMesh.uuid);
if (response) {
removeAsset(selectedMesh.uuid);
echo.success("Model Removed!");
}
selectedMesh.traverse((child: THREE.Object3D) => { selectedMesh.traverse((child: THREE.Object3D) => {
if (child instanceof THREE.Mesh) { if (child instanceof THREE.Mesh) {
if (child.geometry) child.geometry.dispose(); if (child.geometry) child.geometry.dispose();

View File

@ -160,10 +160,6 @@ const KeyPressListener: React.FC = () => {
}; };
const handleKeyPress = (event: KeyboardEvent) => { const handleKeyPress = (event: KeyboardEvent) => {
console.log(
"isTextInput(document.activeElement): ",
isTextInput(document.activeElement)
);
if (isTextInput(document.activeElement)) return; if (isTextInput(document.activeElement)) return;
const keyCombination = detectModifierKeys(event); const keyCombination = detectModifierKeys(event);
@ -172,7 +168,6 @@ const KeyPressListener: React.FC = () => {
return; return;
if (keyCombination === "ESCAPE") { if (keyCombination === "ESCAPE") {
console.log("esc");
setWalkMode(false); setWalkMode(false);
setActiveTool("cursor"); setActiveTool("cursor");
setActiveSubTool("cursor"); setActiveSubTool("cursor");
@ -191,7 +186,6 @@ const KeyPressListener: React.FC = () => {
keyCombination === "Ctrl+R" keyCombination === "Ctrl+R"
) )
return; return;
console.log("keyCombination: ", keyCombination);
event.preventDefault(); event.preventDefault();