Refactor simulation product handling and state management
- Replaced `useComparisonProduct` with `useSimulationState` in multiple components to streamline state management. - Updated `SyncCam` to use `comparisonScene` instead of `comparisonProduct`. - Modified `Products` component to utilize `mainScene` and `comparisonScene` for product selection. - Adjusted various simulation functions to accept `ProductsSchema` instead of `productsSchema`. - Enhanced `Simulator` component to fetch simulation data using the updated state structure. - Refined Zustand store to manage `mainScene` and `comparisonScene` states, including their respective setters and clearers. - Updated type definitions for products to ensure consistency across the application. - Cleaned up shortcut key handling to reflect changes in state management.
This commit is contained in:
@@ -2,7 +2,7 @@ import React, { useEffect, useRef, useState } from "react";
|
||||
import { AddIcon, ArrowIcon, RemoveIcon, ResizeHeightIcon } from "../../../icons/ExportCommonIcons";
|
||||
import RenameInput from "../../../ui/inputs/RenameInput";
|
||||
import { handleResize } from "../../../../functions/handleResizePannel";
|
||||
import { useMainProduct, useSelectedAsset } from "../../../../store/simulation/useSimulationStore";
|
||||
import { useSimulationState, useSelectedAsset } from "../../../../store/simulation/useSimulationStore";
|
||||
import { generateUUID } from "three/src/math/MathUtils";
|
||||
import RenderOverlay from "../../../templates/Overlay";
|
||||
import EditWidgetOption from "../../../ui/menu/EditWidgetOption";
|
||||
@@ -17,8 +17,7 @@ import { useCompareStore, useIsComparing, useSimulateId } from "../../../../stor
|
||||
import { useToggleStore } from "../../../../store/ui/useUIToggleStore";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useSceneContext } from "../../../../modules/scene/sceneContext";
|
||||
import { getSimulationData, updateSimulateData } from "../../scenes/functions/simulationStorage";
|
||||
import { get } from "http";
|
||||
import { updateSimulateData } from "../../scenes/functions/simulationStorage";
|
||||
|
||||
interface Event {
|
||||
modelName: string;
|
||||
@@ -35,7 +34,7 @@ const Simulations: React.FC = () => {
|
||||
const [processes, setProcesses] = useState<Event[][]>();
|
||||
const { setToggleUI } = useToggleStore();
|
||||
const { projectId } = useParams();
|
||||
const { setMainProduct } = useMainProduct();
|
||||
const { setMainState, clearMainState } = useSimulationState();
|
||||
const { selectedVersion } = versionStore();
|
||||
const { comparePopUp, setComparePopUp } = useCompareStore();
|
||||
const { setIsComparing } = useIsComparing();
|
||||
@@ -51,7 +50,6 @@ const Simulations: React.FC = () => {
|
||||
productUuid: selectedProduct?.productUuid || "",
|
||||
simulatedId: simulateId,
|
||||
};
|
||||
console.log("singleData: ", singleData);
|
||||
const getData = await updateSimulateData(singleData);
|
||||
echo.log(getData.message);
|
||||
};
|
||||
@@ -74,17 +72,23 @@ const Simulations: React.FC = () => {
|
||||
|
||||
const updatedProducts = products.filter((p) => p.productUuid !== productUuid);
|
||||
|
||||
if (isSelected) {
|
||||
if (isSelected && selectedVersion) {
|
||||
if (updatedProducts.length > 0) {
|
||||
let newSelectedIndex = currentIndex;
|
||||
if (currentIndex >= updatedProducts.length) {
|
||||
newSelectedIndex = updatedProducts.length - 1;
|
||||
}
|
||||
setSelectedProduct(updatedProducts[newSelectedIndex].productUuid, updatedProducts[newSelectedIndex].productName);
|
||||
setMainProduct(updatedProducts[newSelectedIndex].productUuid, updatedProducts[newSelectedIndex].productName);
|
||||
const data = {
|
||||
productUuid: updatedProducts[newSelectedIndex].productUuid,
|
||||
productName: updatedProducts[newSelectedIndex].productName,
|
||||
versionUuid: selectedVersion.versionId,
|
||||
versionName: selectedVersion.versionName,
|
||||
};
|
||||
setMainState(data);
|
||||
} else {
|
||||
setSelectedProduct("", "");
|
||||
setMainProduct("", "");
|
||||
clearMainState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,9 +103,15 @@ const Simulations: React.FC = () => {
|
||||
const handleRenameProduct = (productUuid: string, newName: string) => {
|
||||
renameProduct(productUuid, newName);
|
||||
renameProductApi({ productName: newName, productUuid, projectId: projectId || "", versionId: selectedVersion?.versionId || "" });
|
||||
if (selectedProduct.productUuid === productUuid) {
|
||||
if (selectedProduct.productUuid === productUuid && selectedVersion) {
|
||||
setSelectedProduct(productUuid, newName);
|
||||
setMainProduct(productUuid, newName);
|
||||
const data = {
|
||||
productUuid: productUuid,
|
||||
productName: newName,
|
||||
versionUuid: selectedVersion.versionId,
|
||||
versionName: selectedVersion.versionName,
|
||||
};
|
||||
setMainState(data);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -136,7 +146,7 @@ const Simulations: React.FC = () => {
|
||||
});
|
||||
}
|
||||
}, [selectedProduct.productUuid, products]);
|
||||
//call when comparePopup is true
|
||||
|
||||
useEffect(() => {
|
||||
if (comparePopUp || selectedProduct.productUuid) {
|
||||
}
|
||||
@@ -173,8 +183,16 @@ const Simulations: React.FC = () => {
|
||||
<div
|
||||
className="value"
|
||||
onClick={() => {
|
||||
setSelectedProduct(product.productUuid, product.productName);
|
||||
setMainProduct(product.productUuid, product.productName);
|
||||
if (selectedVersion) {
|
||||
setSelectedProduct(product.productUuid, product.productName);
|
||||
const data = {
|
||||
productUuid: product.productUuid,
|
||||
productName: product.productName,
|
||||
versionUuid: selectedVersion.versionId,
|
||||
versionName: selectedVersion.versionName,
|
||||
};
|
||||
setMainState(data);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<input type="radio" name="products" checked={selectedProduct.productUuid === product.productUuid} readOnly />
|
||||
|
||||
Reference in New Issue
Block a user