Skip to content

Commit 360666a

Browse files
2 parents d3dcd27 + fc80e63 commit 360666a

File tree

5 files changed

+47
-44
lines changed

5 files changed

+47
-44
lines changed

app/src/components/bottom/CodePreview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const CodePreview: React.FC<{
3434
useEffect(() => {
3535
setDivHeight(height);
3636
}, [height])
37-
console.log(currentComponent.code);
37+
// console.log(currentComponent.code);
3838
return (
3939
<div
4040
ref={wrapper}

app/src/components/main/Annotation.tsx

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,30 @@ function Annotation({
1212
annotations,
1313
}: Annotations) {
1414
const [state, dispatch] = useContext(StateContext);
15-
const [annotation, setAnnotations] = useState('');
15+
const [annotation, setAnnotations] = useState(annotations);
1616
const ref = useRef(null);
1717
// React hook setting the annotation button modal open/close state
1818
const [open, setOpen] = React.useState(false);
1919
const focusIndex = state.canvasFocus.componentId - 1;
2020
const childrenArray = state.components[focusIndex].children;
2121

2222
// For showing the modal
23-
const handleOpen = (id) => {
24-
const childEle = handleFindAnno(childrenArray, id);
23+
const handleOpen = () => {
2524
setOpen(true);
2625
};
27-
26+
2827
// For closing the modal
29-
const handleClose = (id) => {
30-
const focusIndex = state.canvasFocus.componentId - 1;
31-
const childrenArray = state.components[focusIndex].children;
32-
const childEle = handleFindAnno(childrenArray, id);
33-
34-
if(childEle) {
28+
const handleClose = (event) => {
29+
const annoId = Number(event.target.ownerDocument.activeElement.lastChild.id);
30+
const childEle = handleFindAnno(childrenArray, annoId);
31+
// console.log('annoId', annoId);
32+
// console.log('childrenArray????', childrenArray);
33+
// console.log('childElement we are saving state to', childEle);
34+
// console.log('annotation being saved to state', annotation);
35+
if (childEle && annotation !== annotations) {
36+
// console.log('annotation saved to state!!!!!!!!')
3537
childEle.annotations = annotation;
3638
}
37-
3839
setOpen(false);
3940
};
4041

@@ -44,15 +45,11 @@ function Annotation({
4445
*/
4546
const handleAnnoChange = (event) => {
4647
const { value } = event.target;
47-
48-
if(value === '' || value === undefined) {
48+
setAnnotations(value);
49+
if (value === '' || value === undefined) {
4950
ref.current.style.background = '#3ec1ac';
50-
ref.current.id = 'btn' + event.target.id;
51-
setAnnotations(value);
5251
} else {
5352
ref.current.style.background = '#cc99ff';
54-
ref.current.id = 'btn' + event.target.id;
55-
setAnnotations(value);
5653
}
5754
}
5855

@@ -61,46 +58,49 @@ function Annotation({
6158
* where the canvas components are placed
6259
*/
6360
const handleFindAnno = (array, id) => {
64-
for(let i = 0; i < array.length; i++) {
65-
if(array[i].childId === Number(id)) {
66-
return array[i];
61+
let refElement = '';
62+
for (let i = 0; i < array.length; i++) {
63+
const currentElement = array[i];
64+
if (currentElement.childId === id) {
65+
return currentElement;
66+
}
67+
else if (currentElement.children.length > 0) {
68+
refElement = handleFindAnno(currentElement.children, id);
69+
if (refElement !== '') return refElement;
6770
}
71+
}
72+
return refElement;
73+
};
6874

69-
if(array[i].children.length > 0) {
70-
return handleFindAnno(array[i], id);
75+
const annoRefresh = (array) => {
76+
for (const element of array) {
77+
if (element.hasOwnProperty(annotations)) {
78+
console.log('Somthing here', ref);
7179
}
80+
if (element.children.length > 0) return annoRefresh(element.children);
7281
}
73-
return '';
74-
}
82+
};
7583

7684
/**
7785
* This useEffect allows the annotations to remain persistent when changing between root level components on the right panel
7886
*/
7987
useEffect(() => {
80-
const targetElement = handleFindAnno(childrenArray, id);
81-
if (targetElement !== '') {
82-
const event = {
83-
target : { value: targetElement.annotations},
84-
id : id,
85-
}
86-
console.log("is this a value?", event.target.value);
87-
handleAnnoChange(event);
88-
}
89-
}, [state.canvasFocus])
88+
annoRefresh(childrenArray);
89+
}, [state.canvasFocus]);
9090

9191
const body = (
9292
<div className='annotate-position'>
9393
<span className='annotate-textarea-header'>Notes for: {name} ( {id} )</span>
94-
<textarea className='annotate-textarea' id={id.toString()} onChange={handleAnnoChange}>{handleFindAnno(childrenArray, id).annotations}</textarea>
94+
<textarea className='annotate-textarea' id={id.toString()} onChange={handleAnnoChange}>{annotations}</textarea>
9595
</div>
9696
)
9797

9898
return (
9999
<div style={{padding: '1px', float: 'right'}}>
100-
<button className='annotate-button-empty' id={"btn" + id} onClick={() => handleOpen(id)} ref={ref}>Notes</button>
100+
<button className='annotate-button-empty' id={"btn" + id} onClick={() => handleOpen()} ref={ref}>Notes</button>
101101
<Modal
102102
open={open}
103-
onClose={() => handleClose(id)}
103+
onClose={handleClose}
104104
keepMounted={true}
105105
>
106106
{body}

app/src/components/main/DemoRender.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const DemoRender = (props): JSX.Element => {
2121
const componentsToRender = [];
2222
for (const element of array) {
2323
if (element.name !== 'separator') {
24-
console.log('detail from children array', element);
24+
// console.log('detail from children array', element);
2525
const elementType = element.name;
2626
const childId = element.childId;
2727
const elementStyle = element.style;

app/src/helperFunctions/renderChildren.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const renderChildren = (children: ChildElement[]) => {
2727
typeId={typeId}
2828
key={'DirChildComp' + childId.toString() + name}
2929
name={child.name}
30+
annotations={child.annotations}
3031
/>
3132
);
3233
}
@@ -40,6 +41,7 @@ const renderChildren = (children: ChildElement[]) => {
4041
typeId={typeId}
4142
key={'DirChildHTML' + childId.toString() + name}
4243
name={child.name}
44+
annotations={child.annotations}
4345
/>
4446
);
4547
}
@@ -54,6 +56,7 @@ const renderChildren = (children: ChildElement[]) => {
5456
children={children}
5557
key={'DirChildHTMLNest' + childId.toString() + name}
5658
name={child.name}
59+
annotations={child.annotations}
5760
/>
5861
</div>
5962
);

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,6 @@
127127
"cors": "^2.8.5",
128128
"d3": "^6.2.0",
129129
"dotenv": "^8.2.0",
130-
"electron": "^9.4.2",
131-
"electron-debug": "^3.1.0",
132-
"electron-devtools-installer": "^2.2.4",
133-
"electron-splashscreen": "^1.0.0",
134-
"electron-window-manager": "^1.0.6",
135130
"enzyme": "^3.4.1",
136131
"enzyme-adapter-react-16": "^1.2.0",
137132
"eslint-plugin-react-hooks": "^4.2.0",
@@ -186,6 +181,11 @@
186181
"csp-html-webpack-plugin": "^4.0.0",
187182
"css-loader": "^2.1.1",
188183
"dotenv-webpack": "^5.0.1",
184+
"electron": "^9.4.2",
185+
"electron-debug": "^3.1.0",
186+
"electron-devtools-installer": "^2.2.4",
187+
"electron-splashscreen": "^1.0.0",
188+
"electron-window-manager": "^1.0.6",
189189
"electron-builder": "^22.7.0",
190190
"enzyme-to-json": "^3.5.0",
191191
"eslint": "^4.19.1",

0 commit comments

Comments
 (0)