2025-03-25 06:17:41 +00:00
|
|
|
import React, { useEffect, useState, useRef } from "react";
|
|
|
|
import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
|
|
|
|
import Panel from "./Panel";
|
|
|
|
import AddButtons from "./AddButtons";
|
|
|
|
import { useSelectedZoneStore } from "../../../store/useZoneStore";
|
|
|
|
import DisplayZone from "./DisplayZone";
|
2025-03-25 11:00:33 +00:00
|
|
|
import Scene from "../../../modules/scene/scene";
|
2025-03-26 07:02:04 +00:00
|
|
|
import useModuleStore from "../../../store/useModuleStore";
|
2025-03-27 06:58:17 +00:00
|
|
|
import { useDroppedObjectsStore, useZones } from "../../../store/store";
|
|
|
|
import DroppedObjects from "./DroppedFloatingWidgets";
|
2025-03-26 13:00:33 +00:00
|
|
|
|
2025-03-26 06:58:22 +00:00
|
|
|
|
2025-03-25 06:17:41 +00:00
|
|
|
|
|
|
|
type Side = "top" | "bottom" | "left" | "right";
|
|
|
|
|
2025-03-26 06:58:22 +00:00
|
|
|
type FormattedZoneData = Record<
|
|
|
|
string,
|
|
|
|
{
|
|
|
|
activeSides: Side[];
|
|
|
|
panelOrder: Side[];
|
|
|
|
lockedPanels: Side[];
|
2025-03-26 13:00:33 +00:00
|
|
|
zoneId: string;
|
|
|
|
zoneViewPortTarget: number[];
|
|
|
|
zoneViewPortPosition: number[]
|
2025-03-26 06:58:22 +00:00
|
|
|
widgets: Widget[];
|
|
|
|
}
|
|
|
|
>;
|
|
|
|
type Widget = {
|
2025-03-25 06:17:41 +00:00
|
|
|
id: string;
|
|
|
|
type: string;
|
|
|
|
title: string;
|
|
|
|
panel: Side;
|
|
|
|
data: any;
|
2025-03-26 06:58:22 +00:00
|
|
|
};
|
2025-03-25 06:17:41 +00:00
|
|
|
|
|
|
|
const RealTimeVisulization: React.FC = () => {
|
|
|
|
const [hiddenPanels, setHiddenPanels] = React.useState<Side[]>([]);
|
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
|
|
const { isPlaying } = usePlayButtonStore();
|
2025-03-26 07:02:04 +00:00
|
|
|
const { activeModule } = useModuleStore();
|
2025-03-27 06:58:17 +00:00
|
|
|
const [droppedObjects, setDroppedObjects] = useState<any[]>([]);
|
2025-03-26 06:58:22 +00:00
|
|
|
const [zonesData, setZonesData] = useState<FormattedZoneData>({});
|
2025-03-25 06:17:41 +00:00
|
|
|
const { selectedZone, setSelectedZone } = useSelectedZoneStore();
|
2025-03-26 13:00:33 +00:00
|
|
|
const { zones } = useZones()
|
2025-03-26 06:58:22 +00:00
|
|
|
|
2025-03-25 06:17:41 +00:00
|
|
|
useEffect(() => {
|
2025-03-26 13:00:33 +00:00
|
|
|
const data = Array.isArray(zones) ? zones : [];
|
2025-03-27 06:58:17 +00:00
|
|
|
|
2025-03-26 13:00:33 +00:00
|
|
|
const formattedData = data.reduce<FormattedZoneData>((acc, zone) => {
|
|
|
|
acc[zone.zoneName] = {
|
|
|
|
activeSides: [],
|
|
|
|
panelOrder: [],
|
|
|
|
lockedPanels: [],
|
|
|
|
zoneId: zone.zoneId,
|
|
|
|
zoneViewPortTarget: zone.viewPortCenter,
|
|
|
|
zoneViewPortPosition: zone.viewPortposition,
|
|
|
|
widgets: [],
|
|
|
|
};
|
|
|
|
return acc;
|
|
|
|
}, {});
|
2025-03-26 06:58:22 +00:00
|
|
|
|
2025-03-26 13:00:33 +00:00
|
|
|
setZonesData(formattedData);
|
|
|
|
}, [zones]);
|
2025-03-26 06:58:22 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setZonesData((prev) => {
|
|
|
|
if (!selectedZone) return prev;
|
|
|
|
return {
|
|
|
|
...prev,
|
|
|
|
[selectedZone.zoneName]: {
|
|
|
|
...prev[selectedZone.zoneName], // Keep existing properties
|
|
|
|
activeSides: selectedZone.activeSides || [],
|
|
|
|
panelOrder: selectedZone.panelOrder || [],
|
|
|
|
lockedPanels: selectedZone.lockedPanels || [],
|
2025-03-26 13:00:33 +00:00
|
|
|
zoneId: selectedZone.zoneId || "",
|
|
|
|
zoneViewPortTarget: selectedZone.zoneViewPortTarget || [],
|
|
|
|
zoneViewPortPosition: selectedZone.zoneViewPortPosition || [],
|
2025-03-26 06:58:22 +00:00
|
|
|
widgets: selectedZone.widgets || [],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
2025-03-25 06:17:41 +00:00
|
|
|
}, [selectedZone]);
|
|
|
|
|
2025-03-27 06:58:17 +00:00
|
|
|
// const handleDrop = (event: React.DragEvent<HTMLDivElement>) => {
|
|
|
|
// console.log("Drop event fired! ✅");
|
|
|
|
// event.preventDefault();
|
|
|
|
|
|
|
|
// const data = event.dataTransfer.getData("text/plain");
|
|
|
|
// if (!data) {
|
|
|
|
// console.log("❌ No data received on drop!");
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// try {
|
|
|
|
// const droppedData = JSON.parse(data);
|
|
|
|
// console.log("✅ Dropped Data:", droppedData);
|
|
|
|
|
|
|
|
// console.log('droppedData: ', droppedData);
|
|
|
|
// setDroppedObjects((prev) => [...prev, droppedData]); // ✅ Add to state
|
|
|
|
// console.log(droppedObjects);
|
|
|
|
// } catch (error) {
|
|
|
|
// console.error("❌ Error parsing dropped data:", error);
|
|
|
|
// }
|
|
|
|
// };
|
2025-03-26 13:00:33 +00:00
|
|
|
const handleDrop = (event: React.DragEvent<HTMLDivElement>) => {
|
|
|
|
event.preventDefault();
|
2025-03-27 06:58:17 +00:00
|
|
|
const data = event.dataTransfer.getData("text/plain"); // Use "text/plain" to match the drag event
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
const droppedData = JSON.parse(data);
|
|
|
|
useDroppedObjectsStore.getState().addObject(droppedData); // Add to Zustand store
|
2025-03-26 13:00:33 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2025-03-25 06:17:41 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
ref={containerRef}
|
|
|
|
id="real-time-vis-canvas"
|
2025-03-26 08:22:10 +00:00
|
|
|
className={`realTime-viz canvas ${isPlaying ? "playingFlase" : ""}`}
|
2025-03-25 06:17:41 +00:00
|
|
|
style={{
|
2025-03-26 07:02:04 +00:00
|
|
|
height: isPlaying || activeModule !== "visualization" ? "100vh" : "",
|
|
|
|
width: isPlaying || activeModule !== "visualization" ? "100vw" : "",
|
|
|
|
left: isPlaying || activeModule !== "visualization" ? "0%" : "",
|
2025-03-25 06:17:41 +00:00
|
|
|
}}
|
|
|
|
>
|
2025-03-25 11:00:33 +00:00
|
|
|
<div
|
|
|
|
className="scene-container"
|
2025-03-26 07:02:04 +00:00
|
|
|
style={{
|
|
|
|
height: "100%",
|
|
|
|
width: "100%",
|
|
|
|
borderRadius: isPlaying || activeModule !== "visualization" ? "" : "6px",
|
|
|
|
}}
|
2025-03-27 06:58:17 +00:00
|
|
|
onDrop={(event) => handleDrop(event)}
|
|
|
|
onDragOver={(event) => event.preventDefault()}
|
2025-03-25 11:00:33 +00:00
|
|
|
>
|
2025-03-27 06:58:17 +00:00
|
|
|
|
2025-03-25 11:00:33 +00:00
|
|
|
<Scene />
|
|
|
|
</div>
|
2025-03-26 07:02:04 +00:00
|
|
|
{activeModule === "visualization" && (
|
|
|
|
<>
|
|
|
|
<DisplayZone
|
|
|
|
zonesData={zonesData}
|
|
|
|
selectedZone={selectedZone}
|
|
|
|
setSelectedZone={setSelectedZone}
|
|
|
|
/>
|
|
|
|
|
2025-03-26 13:00:33 +00:00
|
|
|
{!isPlaying && selectedZone?.zoneName !== "" && (
|
2025-03-26 07:02:04 +00:00
|
|
|
<AddButtons
|
|
|
|
hiddenPanels={hiddenPanels}
|
|
|
|
setHiddenPanels={setHiddenPanels}
|
|
|
|
selectedZone={selectedZone}
|
|
|
|
setSelectedZone={setSelectedZone}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<Panel
|
2025-03-26 13:00:33 +00:00
|
|
|
hiddenPanels={hiddenPanels}
|
2025-03-26 07:02:04 +00:00
|
|
|
selectedZone={selectedZone}
|
|
|
|
setSelectedZone={setSelectedZone}
|
2025-03-27 06:58:17 +00:00
|
|
|
|
2025-03-26 07:02:04 +00:00
|
|
|
/>
|
|
|
|
</>
|
2025-03-25 11:00:33 +00:00
|
|
|
)}
|
2025-03-25 06:17:41 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default RealTimeVisulization;
|