Skip to content

Commit bdcf7ae

Browse files
committed
nested links working
1 parent 480d8e1 commit bdcf7ae

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

app/src/components/main/AddLink.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,21 @@ function AddLink({ id, onClickHandler, linkDisplayed }) {
1414
const [state, dispatch] = useContext(StateContext);
1515
const [link, setLink] = useState('')
1616

17+
function deepIterate(arr) {
18+
const output = [];
19+
for(let i = 0; i < arr.length; i++) {
20+
if(arr[i].typeId === 1000) continue;
21+
output.push(arr[i]);
22+
if(arr[i].children.length) {
23+
output.push(...deepIterate(arr[i].children));
24+
}
25+
}
26+
return output;
27+
}
28+
1729
const handlePageSelect = event => {
18-
console.log('hit');
1930
const currComponent = state.components.find(element => element.id === state.canvasFocus.componentId);
20-
currComponent.children.some(element => {
31+
deepIterate(currComponent.children).some(element => {
2132
if(element.childId === id) {
2233
const state = JSON.parse(JSON.stringify(element));
2334
state.childId = id;

0 commit comments

Comments
 (0)