From 4a5b62a1b0e301fe4b5f8524e46e3fa1e6e20fcb Mon Sep 17 00:00:00 2001 From: rsdexter Date: Mon, 27 Apr 2020 21:13:05 -0400 Subject: [PATCH] Iteration adds the selection as a child of itself, but does so properly --- src/canvas/Canvas.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/canvas/Canvas.js b/src/canvas/Canvas.js index 9ef31c6..2c4c6c6 100644 --- a/src/canvas/Canvas.js +++ b/src/canvas/Canvas.js @@ -160,7 +160,7 @@ class Canvas extends React.Component { console.log("Insert ID could not be found in Iterate"); return false; } - //insert.data = insert.data.concat(copy); + insert.data = insert.data.concat(copy); console.log(copy, insert); currentStep+=1; steps.push(step); @@ -272,12 +272,17 @@ class Canvas extends React.Component { // Also updates the state.data map according to new generated IDs function copyDataMap(map) { let newMap = {}; - let id = nanoid(); for (let m in map) { // If an ID is found, generate a new one if (m === 'id') { console.log("ID FOUND", map[m]) - newMap[m] = nanoid(); + let id = nanoid(); + newMap[m] = id; + // Add the new data to state.data via a deep copy + data[id] = { + type: "cut", + level: data[map[m]].level + } } // Otherwise, if not a data array, copy the contents else if (m !== 'data'){ @@ -299,6 +304,13 @@ class Canvas extends React.Component { if (typeof arr[a] === 'string') { let id = nanoid(); newArr.push(id); + // Add the new data to state.data via a deep copy + data[id] = { + type: "var", + var: data[arr[a]].var, + x: data[arr[a]].x, + y: data[arr[a]].y, + } } // otherwise, call the other helper function to copy contents else { @@ -309,6 +321,7 @@ class Canvas extends React.Component { } let newStep = copyDataMap(step); console.log(newStep, step); + this.setState({ data: data }) return newStep; } -- 2.51.2