refactor api-simulation for create and fetch
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useActionHandler } from '../actions/useActionHandler';
|
||||
import { usePlayButtonStore, useResetButtonStore } from '../../../store/usePlayButtonStore';
|
||||
import { determineExecutionOrder } from './functions/determineExecutionOrder';
|
||||
import { useProductContext } from '../products/productContext';
|
||||
import { useSceneContext } from '../../scene/sceneContext';
|
||||
import SimulationHandler from './SimulationHandler';
|
||||
import { useEffect } from "react";
|
||||
import { useActionHandler } from "../actions/useActionHandler";
|
||||
import { usePlayButtonStore, useResetButtonStore } from "../../../store/usePlayButtonStore";
|
||||
import { determineExecutionOrder } from "./functions/determineExecutionOrder";
|
||||
import { useProductContext } from "../products/productContext";
|
||||
import { useSceneContext } from "../../scene/sceneContext";
|
||||
import SimulationHandler from "./SimulationHandler";
|
||||
import { getSimulationData, saveSimulationData } from "../../../components/layout/scenes/functions/simulationStorage";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useVersionContext } from "../../builder/version/versionContext";
|
||||
import { version } from "os";
|
||||
import { get } from "http";
|
||||
import { useSimulationManager } from "../../../store/rough/useSimulationManagerStore";
|
||||
|
||||
function Simulator() {
|
||||
const { selectedProductStore } = useProductContext();
|
||||
@@ -14,6 +20,9 @@ function Simulator() {
|
||||
const { selectedProduct } = selectedProductStore();
|
||||
const { isPlaying } = usePlayButtonStore();
|
||||
const { isReset } = useResetButtonStore();
|
||||
const { projectId } = useParams();
|
||||
const { selectedVersionStore } = useVersionContext();
|
||||
const { selectedVersion } = selectedVersionStore();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isPlaying || isReset || !selectedProduct.productUuid) return;
|
||||
@@ -23,22 +32,41 @@ function Simulator() {
|
||||
|
||||
const executionOrder = determineExecutionOrder([product]);
|
||||
|
||||
executionOrder.forEach(action => {
|
||||
executionOrder.forEach((action) => {
|
||||
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 product = getProductById(selectedProduct.productUuid);
|
||||
if (!product) return;
|
||||
const products: productsSchema = [product];
|
||||
const getSimulate = getData?.data;
|
||||
if (getData && getSimulate && getSimulate.productTimestamp === products[0]?.timestamp) {
|
||||
return;
|
||||
} else {
|
||||
//call create API
|
||||
const data = {
|
||||
projectId: projectId,
|
||||
versionId: selectedVersion.versionId,
|
||||
productUuid: selectedProduct.productUuid,
|
||||
simulateData: useSimulationManager.getState().getProductById(projectId, selectedVersion?.versionId, selectedProduct.productUuid)?.simulateData,
|
||||
};
|
||||
const simulations = await saveSimulationData(data);
|
||||
console.log("simulations: ", simulations);
|
||||
echo.log("Simulation data saved successfully");
|
||||
}
|
||||
};
|
||||
fetchSimulateData();
|
||||
}, []);
|
||||
return (
|
||||
|
||||
<>
|
||||
|
||||
{/* <simulationHandler/> */}
|
||||
<SimulationHandler />
|
||||
|
||||
</>
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
export default Simulator;
|
||||
export default Simulator;
|
||||
|
||||
Reference in New Issue
Block a user