Skip to content

Commit

Permalink
Fix mistake in indentations
Browse files Browse the repository at this point in the history
  • Loading branch information
RitikDutta authored Dec 28, 2024
1 parent 542d5c1 commit b03752f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions autogpt_platform/frontend/src/hooks/useCopyPaste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function useCopyPaste(getNextNodeId: () => string) {
if (event.key === "c" || event.key === "C") {
const selectedNodes = getNodes().filter((node) => node.selected);
const selectedEdges = getEdges().filter((edge) => edge.selected);

const copiedData = {
nodes: selectedNodes.map((node) => ({
...node,
Expand All @@ -22,20 +22,20 @@ export function useCopyPaste(getNextNodeId: () => string) {
})),
edges: selectedEdges,
};

localStorage.setItem("copiedFlowData", JSON.stringify(copiedData));
}
if (event.key === "v" || event.key === "V") {
const copiedDataString = localStorage.getItem("copiedFlowData");
if (copiedDataString) {
const copiedData = JSON.parse(copiedDataString);
const oldToNewIdMap: Record<string, string> = {};

const viewportCenter = {
x: (window.innerWidth / 2 - x) / zoom,
y: (window.innerHeight / 2 - y) / zoom,
};

let minX = Infinity,
minY = Infinity,
maxX = -Infinity,
Expand All @@ -46,10 +46,10 @@ export function useCopyPaste(getNextNodeId: () => string) {
maxX = Math.max(maxX, node.position.x);
maxY = Math.max(maxY, node.position.y);
});

const offsetX = viewportCenter.x - (minX + maxX) / 2;
const offsetY = viewportCenter.y - (minY + maxY) / 2;

const pastedNodes = copiedData.nodes.map((node: Node) => {
const newNodeId = getNextNodeId();
oldToNewIdMap[node.id] = newNodeId;
Expand All @@ -68,7 +68,7 @@ export function useCopyPaste(getNextNodeId: () => string) {
},
};
});

const pastedEdges = copiedData.edges.map((edge: Edge) => {
const newSourceId = oldToNewIdMap[edge.source] ?? edge.source;
const newTargetId = oldToNewIdMap[edge.target] ?? edge.target;
Expand All @@ -79,13 +79,13 @@ export function useCopyPaste(getNextNodeId: () => string) {
target: newTargetId,
};
});

setNodes((existingNodes) => [
...existingNodes.map((node) => ({ ...node, selected: false })),
...pastedNodes,
]);
addEdges(pastedEdges);

setNodes((nodes) => {
return nodes.map((node) => {
if (oldToNewIdMap[node.id]) {
Expand Down Expand Up @@ -118,6 +118,6 @@ export function useCopyPaste(getNextNodeId: () => string) {
},
[setNodes, addEdges, getNodes, getEdges, getNextNodeId, x, y, zoom],
);

return handleCopyPaste;
}
}

0 comments on commit b03752f

Please sign in to comment.