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:
@@ -5,7 +5,10 @@ import { determineExecutionOrder } from "./functions/determineExecutionOrder";
|
||||
import { useSceneContext } from "../../scene/sceneContext";
|
||||
import SimulationHandler from "./SimulationHandler";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { getSimulationData, saveSimulationData } from "../../../components/layout/scenes/functions/simulationStorage";
|
||||
import {
|
||||
getSimulationData,
|
||||
saveSimulationData,
|
||||
} from "../../../components/layout/scenes/functions/simulationStorage";
|
||||
import { useSimulationManager } from "../../../store/rough/useSimulationManagerStore";
|
||||
import { useSimulateId } from "../../../store/builder/store";
|
||||
|
||||
@@ -32,18 +35,23 @@ function Simulator() {
|
||||
handleAction(action);
|
||||
});
|
||||
}, [products, isPlaying, isReset, selectedProduct]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!projectId || !selectedVersion || !selectedProduct?.productUuid) return;
|
||||
const fetchSimulateData = async () => {
|
||||
const getData = await getSimulationData(projectId, selectedVersion.versionId, selectedProduct?.productUuid);
|
||||
const getData = await getSimulationData(
|
||||
projectId,
|
||||
selectedVersion.versionId,
|
||||
selectedProduct?.productUuid
|
||||
);
|
||||
const product = getProductById(selectedProduct.productUuid);
|
||||
if (!product) return;
|
||||
const products: productsSchema = [product];
|
||||
const products: ProductsSchema = [product];
|
||||
const getSimulate = getData?.data;
|
||||
console.log("getSimulate: ", getSimulate);
|
||||
// console.log("getSimulate: ", getSimulate);
|
||||
if (getData && getSimulate && getSimulate.productTimestamp === products[0]?.timestamp) {
|
||||
setSimulateId(getSimulate._id);
|
||||
console.log(" getSimulate.data: ", getSimulate.data);
|
||||
// console.log(" getSimulate.data: ", getSimulate.data);
|
||||
addSimulationRecords(
|
||||
projectId,
|
||||
selectedVersion?.versionId || "",
|
||||
@@ -58,15 +66,22 @@ function Simulator() {
|
||||
projectId: projectId,
|
||||
versionId: selectedVersion.versionId,
|
||||
productUuid: selectedProduct.productUuid,
|
||||
simulateData: useSimulationManager.getState().getProductById(projectId, selectedVersion?.versionId, selectedProduct.productUuid)?.simulateData,
|
||||
simulateData: useSimulationManager
|
||||
.getState()
|
||||
.getProductById(
|
||||
projectId,
|
||||
selectedVersion?.versionId,
|
||||
selectedProduct.productUuid
|
||||
)?.simulateData,
|
||||
};
|
||||
const simulations = await saveSimulationData(data);
|
||||
console.log("simulations: ", simulations);
|
||||
// console.log("simulations: ", simulations);
|
||||
echo.log("Simulation data saved successfully");
|
||||
}
|
||||
};
|
||||
fetchSimulateData();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* <simulationHandler/> */}
|
||||
|
||||
Reference in New Issue
Block a user