2025-06-12 06:37:28 +00:00
|
|
|
import React, { useEffect } from "react";
|
2025-06-04 12:32:38 +00:00
|
|
|
import {
|
|
|
|
useLoadingProgress,
|
2025-06-11 05:14:13 +00:00
|
|
|
useRenameModeStore,
|
2025-06-04 12:32:38 +00:00
|
|
|
useSaveVersion,
|
2025-06-11 05:14:13 +00:00
|
|
|
useSelectedFloorItem,
|
2025-06-04 12:32:38 +00:00
|
|
|
useSocketStore,
|
|
|
|
useWidgetSubOption,
|
|
|
|
} from "../../../store/builder/store";
|
|
|
|
import useModuleStore, { useThreeDStore } from "../../../store/useModuleStore";
|
|
|
|
import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
|
|
|
|
import { useSelectedZoneStore } from "../../../store/visualization/useZoneStore";
|
|
|
|
import { useFloatingWidget } from "../../../store/visualization/useDroppedObjectsStore";
|
|
|
|
import { useSelectedUserStore } from "../../../store/collaboration/useCollabStore";
|
|
|
|
import KeyPressListener from "../../../utils/shortcutkeys/handleShortcutKeys";
|
|
|
|
import LoadingPage from "../../templates/LoadingPage";
|
|
|
|
import ModuleToggle from "../../ui/ModuleToggle";
|
|
|
|
import SideBarLeft from "../sidebarLeft/SideBarLeft";
|
|
|
|
import SideBarRight from "../sidebarRight/SideBarRight";
|
|
|
|
import RealTimeVisulization from "../../../modules/visualization/RealTimeVisulization";
|
|
|
|
import MarketPlace from "../../../modules/market/MarketPlace";
|
|
|
|
import Tools from "../../ui/Tools";
|
|
|
|
import SimulationPlayer from "../../ui/simulation/simulationPlayer";
|
|
|
|
import ControlsPlayer from "../controls/ControlsPlayer";
|
|
|
|
import SelectFloorPlan from "../../temporary/SelectFloorPlan";
|
|
|
|
import { createHandleDrop } from "../../../modules/visualization/functions/handleUiDrop";
|
|
|
|
import Scene from "../../../modules/scene/scene";
|
2025-06-05 05:04:46 +00:00
|
|
|
import {
|
|
|
|
useComparisonProduct,
|
|
|
|
useMainProduct,
|
|
|
|
} from "../../../store/simulation/useSimulationStore";
|
2025-06-04 12:32:38 +00:00
|
|
|
import { useProductContext } from "../../../modules/simulation/products/productContext";
|
|
|
|
import { useProductStore } from "../../../store/simulation/useProductStore";
|
|
|
|
import RegularDropDown from "../../ui/inputs/RegularDropDown";
|
2025-06-11 05:14:13 +00:00
|
|
|
import RenameTooltip from "../../ui/features/RenameTooltip";
|
|
|
|
import { setFloorItemApi } from "../../../services/factoryBuilder/assest/floorAsset/setFloorItemApi";
|
|
|
|
import { useAssetsStore } from "../../../store/builder/useAssetStore";
|
2025-06-11 05:22:10 +00:00
|
|
|
import { useParams } from "react-router-dom";
|
Refactor user data retrieval across visualization components
- Replaced direct localStorage access for email and organization with a centralized getUserData function in LineGraphComponent, PieGraphComponent, PolarAreaGraphComponent, ProgressCard1, ProgressCard2, Dropped3dWidgets, ProductionCapacity, ReturnOfInvestment, StateWorking, Throughput, and various floating widgets.
- Improved code readability and maintainability by consolidating user data extraction logic.
- Ensured consistent user data handling across multiple components to reduce redundancy.
2025-06-13 11:41:28 +00:00
|
|
|
import { getUserData } from "../../../functions/getUserData";
|
2025-05-29 06:30:16 +00:00
|
|
|
|
|
|
|
function MainScene() {
|
2025-06-04 12:32:38 +00:00
|
|
|
const { products } = useProductStore();
|
|
|
|
const { setMainProduct } = useMainProduct();
|
|
|
|
const { selectedProductStore } = useProductContext();
|
|
|
|
const { selectedProduct } = selectedProductStore();
|
2025-06-12 06:37:28 +00:00
|
|
|
const { isVersionSaved, setIsVersionSaved } = useSaveVersion();
|
2025-06-04 12:32:38 +00:00
|
|
|
const { activeModule } = useModuleStore();
|
|
|
|
const { selectedUser } = useSelectedUserStore();
|
|
|
|
const { loadingProgress } = useLoadingProgress();
|
|
|
|
const { toggleThreeD } = useThreeDStore();
|
|
|
|
const { isPlaying } = usePlayButtonStore();
|
|
|
|
const { widgetSubOption } = useWidgetSubOption();
|
|
|
|
const { visualizationSocket } = useSocketStore();
|
|
|
|
const { selectedZone } = useSelectedZoneStore();
|
|
|
|
const { setFloatingWidget } = useFloatingWidget();
|
2025-06-13 12:45:35 +00:00
|
|
|
const { comparisonProduct, clearComparisonProduct } = useComparisonProduct();
|
2025-06-11 05:14:13 +00:00
|
|
|
const { selectedFloorItem, setSelectedFloorItem } = useSelectedFloorItem();
|
|
|
|
const { setName } = useAssetsStore();
|
2025-06-11 05:22:10 +00:00
|
|
|
const { projectId } = useParams()
|
2025-06-11 05:14:13 +00:00
|
|
|
const { isRenameMode, setIsRenameMode } = useRenameModeStore();
|
Refactor user data retrieval across visualization components
- Replaced direct localStorage access for email and organization with a centralized getUserData function in LineGraphComponent, PieGraphComponent, PolarAreaGraphComponent, ProgressCard1, ProgressCard2, Dropped3dWidgets, ProductionCapacity, ReturnOfInvestment, StateWorking, Throughput, and various floating widgets.
- Improved code readability and maintainability by consolidating user data extraction logic.
- Ensured consistent user data handling across multiple components to reduce redundancy.
2025-06-13 11:41:28 +00:00
|
|
|
const { userName, userId, organization, email } = getUserData();
|
2025-06-12 06:37:28 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (activeModule !== 'simulation') {
|
|
|
|
clearComparisonProduct();
|
|
|
|
setIsVersionSaved(false);
|
|
|
|
}
|
|
|
|
}, [activeModule])
|
|
|
|
|
2025-06-10 06:19:30 +00:00
|
|
|
const handleSelectLayout = (option: string) => {
|
|
|
|
const product = products.find((product) => product.productName === option);
|
|
|
|
if (product) {
|
|
|
|
setMainProduct(product.productUuid, product.productName);
|
|
|
|
}
|
|
|
|
};
|
2025-06-11 05:14:13 +00:00
|
|
|
const handleObjectRename = async (newName: string) => {
|
2025-06-12 04:14:53 +00:00
|
|
|
if (!projectId) return
|
2025-06-11 05:14:13 +00:00
|
|
|
let response = await setFloorItemApi(
|
|
|
|
organization,
|
|
|
|
selectedFloorItem.userData.modelUuid,
|
2025-06-11 05:22:10 +00:00
|
|
|
newName,
|
|
|
|
projectId
|
2025-06-11 05:14:13 +00:00
|
|
|
);
|
2025-06-11 06:16:58 +00:00
|
|
|
selectedFloorItem.userData = {
|
|
|
|
...selectedFloorItem.userData,
|
|
|
|
modelName: newName
|
|
|
|
};
|
2025-06-11 05:14:13 +00:00
|
|
|
setSelectedFloorItem(selectedFloorItem);
|
|
|
|
setIsRenameMode(false);
|
2025-06-11 06:16:58 +00:00
|
|
|
setName(selectedFloorItem.userData.modelUuid, response.modelName);
|
2025-06-11 05:14:13 +00:00
|
|
|
}
|
2025-05-29 06:30:16 +00:00
|
|
|
|
2025-06-04 12:32:38 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{!selectedUser && (
|
2025-05-29 06:30:16 +00:00
|
|
|
<>
|
2025-06-04 12:32:38 +00:00
|
|
|
<KeyPressListener />
|
|
|
|
{loadingProgress > 0 && <LoadingPage progress={loadingProgress} />}
|
|
|
|
{!isPlaying && (
|
|
|
|
<>
|
|
|
|
{toggleThreeD && <ModuleToggle />}
|
|
|
|
<SideBarLeft />
|
|
|
|
<SideBarRight />
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
<RealTimeVisulization />
|
|
|
|
{activeModule === "market" && <MarketPlace />}
|
|
|
|
{activeModule !== "market" && !isPlaying && !isVersionSaved && (
|
|
|
|
<Tools />
|
|
|
|
)}
|
2025-06-12 06:37:28 +00:00
|
|
|
{(isPlaying) &&
|
2025-06-05 07:25:49 +00:00
|
|
|
activeModule === "simulation" &&
|
|
|
|
loadingProgress == 0 && <SimulationPlayer />}
|
2025-06-12 06:37:28 +00:00
|
|
|
{(isPlaying) &&
|
2025-06-05 07:31:38 +00:00
|
|
|
activeModule !== "simulation" && <ControlsPlayer />}
|
2025-05-29 06:30:16 +00:00
|
|
|
|
2025-06-11 05:14:13 +00:00
|
|
|
{isRenameMode && selectedFloorItem?.userData.modelName && <RenameTooltip name={selectedFloorItem?.userData.modelName} onSubmit={handleObjectRename} />}
|
2025-06-04 12:32:38 +00:00
|
|
|
{/* remove this later */}
|
|
|
|
{activeModule === "builder" && !toggleThreeD && <SelectFloorPlan />}
|
2025-05-29 06:30:16 +00:00
|
|
|
</>
|
2025-06-04 12:32:38 +00:00
|
|
|
)}
|
|
|
|
<div
|
2025-06-13 12:45:35 +00:00
|
|
|
className={`scene-container${
|
|
|
|
comparisonProduct?.productUuid ? " half-view" : ""
|
|
|
|
}`}
|
2025-06-04 12:32:38 +00:00
|
|
|
id="work-space-three-d-canvas"
|
|
|
|
style={{
|
|
|
|
height: isPlaying || activeModule !== "visualization" ? "100vh" : "",
|
|
|
|
width: isPlaying || activeModule !== "visualization" ? "100vw" : "",
|
|
|
|
left: isPlaying || activeModule !== "visualization" ? "0%" : "",
|
|
|
|
borderRadius:
|
|
|
|
isPlaying || activeModule !== "visualization" ? "" : "6px",
|
|
|
|
}}
|
|
|
|
role="application"
|
|
|
|
onDrop={(event) =>
|
|
|
|
createHandleDrop({
|
|
|
|
widgetSubOption,
|
|
|
|
visualizationSocket,
|
|
|
|
selectedZone,
|
|
|
|
setFloatingWidget,
|
|
|
|
event,
|
2025-06-13 12:20:23 +00:00
|
|
|
projectId
|
2025-06-04 12:32:38 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
onDragOver={(event) => event.preventDefault()}
|
|
|
|
>
|
|
|
|
<Scene layout="Main Layout" />
|
|
|
|
</div>
|
|
|
|
|
2025-06-10 06:19:30 +00:00
|
|
|
{selectedProduct && isVersionSaved && !isPlaying && activeModule === "simulation" && (
|
2025-06-04 12:32:38 +00:00
|
|
|
<div className="selectLayout-wrapper">
|
|
|
|
<RegularDropDown
|
|
|
|
header={selectedProduct.productName}
|
|
|
|
options={products.map((l) => l.productName)} // Pass layout names as options
|
|
|
|
onSelect={handleSelectLayout}
|
|
|
|
search={false}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
2025-05-29 06:30:16 +00:00
|
|
|
}
|
|
|
|
|
2025-06-04 12:32:38 +00:00
|
|
|
export default MainScene;
|