import React, { useEffect, useRef } from "react"; import { AddIcon, ArrowIcon, RemoveIcon, ResizeHeightIcon, } from "../../../icons/ExportCommonIcons"; import RenameInput from "../../../ui/inputs/RenameInput"; import { handleResize } from "../../../../functions/handleResizePannel"; import { useSelectedAsset, useSelectedProduct } from "../../../../store/simulation/useSimulationStore"; import { useProductStore } from "../../../../store/simulation/useProductStore"; import { generateUUID } from "three/src/math/MathUtils"; import RenderOverlay from "../../../templates/Overlay"; import EditWidgetOption from "../../../ui/menu/EditWidgetOption"; interface Event { pathName: string; } interface ListProps { val: Event; } const List: React.FC = ({ val }) => { return (
{val.pathName}
); }; const Simulations: React.FC = () => { const productsContainerRef = useRef(null); const { products, addProduct, removeProduct, renameProduct, addEvent, removeEvent } = useProductStore(); const { selectedProduct, setSelectedProduct } = useSelectedProduct(); const { selectedAsset, clearSelectedAsset } = useSelectedAsset(); const handleAddProduct = () => { addProduct(`Product ${products.length + 1}`, generateUUID()); }; const handleRemoveProduct = (productId: string) => { const currentIndex = products.findIndex(p => p.productId === productId); const isSelected = selectedProduct.productId === productId; const updatedProducts = products.filter(p => p.productId !== productId); if (isSelected) { if (updatedProducts.length > 0) { let newSelectedIndex = currentIndex; if (currentIndex >= updatedProducts.length) { newSelectedIndex = updatedProducts.length - 1; } setSelectedProduct( updatedProducts[newSelectedIndex].productId, updatedProducts[newSelectedIndex].productName ); } else { setSelectedProduct('', ''); } } removeProduct(productId); }; const handleRenameProduct = (productId: string, newName: string) => { renameProduct(productId, newName); if (selectedProduct.productId === productId) { setSelectedProduct(productId, newName); } }; const handleAddEventToProduct = () => { if (selectedAsset) { addEvent(selectedProduct.productId, selectedAsset); clearSelectedAsset(); } }; const handleRemoveEventFromProduct = () => { if (selectedAsset) { removeEvent(selectedProduct.productId, selectedAsset.modelUuid); clearSelectedAsset(); } }; const selectedProductData = products.find( (product) => product.productId === selectedProduct.productId ); const events: Event[] = selectedProductData?.eventDatas.map((event) => ({ pathName: event.modelName, })) || []; return (
Simulations
Products
Add
{products.map((product, index) => (
setSelectedProduct(product.productId, product.productName)} > handleRenameProduct(product.productId, newName)} />
{products.length > 1 && (
handleRemoveProduct(product.productId)} >
)}
))}
handleResize(e, productsContainerRef)} >
Events
{events.map((event, index) => ( ))}
Need to Compare Layout?
Click 'Compare' to review and analyze the layout differences between them.
{selectedAsset && { if (option === 'Add to Product') { handleAddEventToProduct(); } else { handleRemoveEventFromProduct(); } }} /> }
); }; export default Simulations;