Merge branch 'main-dev' of http://185.100.212.76:7778/Dwinzo-Beta/Dwinzo_Demo into main-dev
This commit is contained in:
@@ -3,6 +3,7 @@ import React, { useState, useRef, useEffect } from "react";
|
||||
import { dataModelManager } from "./data/dataModel";
|
||||
import ControlPanel from "./ControlPanel";
|
||||
import SwapModal from "./SwapModal";
|
||||
import { Block } from "../../types/exportedTypes";
|
||||
import DataModelPanel from "./components/models/DataModelPanel";
|
||||
|
||||
import { useSceneContext } from "../../modules/scene/sceneContext";
|
||||
@@ -77,23 +78,35 @@ const DashboardEditor: React.FC = () => {
|
||||
const currentBlock = blocks.find((b) => b.blockUuid === selectedBlock);
|
||||
const currentElement = currentBlock?.elements.find((el) => el.elementUuid === selectedElement);
|
||||
|
||||
useEffect(() => {
|
||||
console.log("blocks: ", blocks);
|
||||
}, [blocks]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!projectId || !selectedVersion) return;
|
||||
// getDashBoardBlocksApi(projectId, selectedVersion.versionId).then((data) => {
|
||||
// if (data.data && data.data.blocks) {
|
||||
// console.log("data: ", data);
|
||||
// setBlocks(data.data.blocks);
|
||||
// }
|
||||
// });
|
||||
getDashBoardBlocksApi(projectId, selectedVersion.versionId).then((data) => {
|
||||
if (data.data?.blocks) {
|
||||
console.log("data.data.blocks: ", data.data.blocks);
|
||||
setBlocks(data.data.blocks);
|
||||
}
|
||||
});
|
||||
}, [projectId, selectedVersion]);
|
||||
|
||||
const updateBackend = (blocks: Block[]) => {
|
||||
if (!projectId || !selectedVersion) return;
|
||||
|
||||
upsetDashBoardBlocksApi({ projectId, versionId: selectedVersion.versionId, blocks }).then((data) => {
|
||||
if (data.data?.blocks) {
|
||||
console.log("data.data.blocks: ", data.data.blocks);
|
||||
setBlocks(data.data.blocks);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const unsubscribe = subscribe(() => {
|
||||
if (!projectId || !selectedVersion) return;
|
||||
|
||||
// upsetDashBoardBlocksApi({ projectId, versionId: selectedVersion.versionId, blocks }).then((data) => {
|
||||
// console.log("data: ", data);
|
||||
// });
|
||||
updateBackend(blocks);
|
||||
});
|
||||
|
||||
return () => {
|
||||
@@ -103,10 +116,11 @@ const DashboardEditor: React.FC = () => {
|
||||
|
||||
useCallBackOnKey(
|
||||
() => {
|
||||
console.log(blocks);
|
||||
if (!projectId || !selectedVersion) return;
|
||||
updateBackend(blocks);
|
||||
},
|
||||
"Ctrl+S",
|
||||
{ dependencies: [blocks], noRepeat: true, allowOnInput: true }
|
||||
{ dependencies: [blocks, projectId, selectedVersion], noRepeat: true, allowOnInput: true }
|
||||
);
|
||||
|
||||
// Subscribe to data model changes
|
||||
@@ -118,27 +132,27 @@ const DashboardEditor: React.FC = () => {
|
||||
const keys = dataModelManager.getAvailableKeys();
|
||||
const subscriptions: Array<[string, () => void]> = [];
|
||||
|
||||
keys.forEach((key) => {
|
||||
for (const key of keys) {
|
||||
const callback = () => handleDataChange();
|
||||
dataModelManager.subscribe(key, callback);
|
||||
subscriptions.push([key, callback]);
|
||||
});
|
||||
}
|
||||
|
||||
const interval = setInterval(() => {
|
||||
const currentKeys = dataModelManager.getAvailableKeys();
|
||||
const newKeys = currentKeys.filter((key) => !keys.includes(key));
|
||||
|
||||
newKeys.forEach((key) => {
|
||||
for (const key of newKeys) {
|
||||
const callback = () => handleDataChange();
|
||||
dataModelManager.subscribe(key, callback);
|
||||
subscriptions.push([key, callback]);
|
||||
});
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
return () => {
|
||||
subscriptions.forEach(([key, callback]) => {
|
||||
for (const [key, callback] of subscriptions) {
|
||||
dataModelManager.unsubscribe(key, callback);
|
||||
});
|
||||
}
|
||||
clearInterval(interval);
|
||||
};
|
||||
}, []);
|
||||
@@ -239,7 +253,7 @@ const DashboardEditor: React.FC = () => {
|
||||
const deltaY = e.clientY - resizeStart.y;
|
||||
|
||||
const currentBlock = blocks.find((b) => b.blockUuid === resizingBlock);
|
||||
const minSize = currentBlock ? calculateMinBlockSize(currentBlock) : { width: 300, height: 200 };
|
||||
const minSize = currentBlock ? calculateMinBlockSize(currentBlock) : { width: 100, height: 50 };
|
||||
|
||||
const newWidth = Math.max(minSize.width, resizeStart.width + deltaX);
|
||||
const newHeight = Math.max(minSize.height, resizeStart.height + deltaY);
|
||||
|
||||
Reference in New Issue
Block a user