Skip to content

Commit 0b62141

Browse files
authored
Merge pull request #23 from buddhajjigae/annotation-feature
Annotation feature final update
2 parents da08b52 + 2657dd2 commit 0b62141

File tree

6 files changed

+55
-48
lines changed

6 files changed

+55
-48
lines changed

app/src/components/bottom/CodePreview.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const CodePreview: React.FC<{
3434
useEffect(() => {
3535
setDivHeight(height);
3636
}, [height])
37+
3738
return (
3839
<div
3940
ref={wrapper}

app/src/components/login/SignIn.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
7070
const FBAPPID = process.env.REACT_APP_FB_APP_ID;
7171

7272
// this useEffect will check for cookies and set an item in localstorage for github Oauth session validation
73-
useEffect(() => {
73+
74+
// Caret start
75+
// Commented because window api is broken. Work in progress
76+
/* useEffect(() => {
7477
const githubCookie = setInterval(() => {
7578
window.api.setCookie();
7679
window.api.getCookie(cookie => {
@@ -85,7 +88,8 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
8588
}
8689
});
8790
}, 2000);
88-
}, []);
91+
}, []);*/
92+
// Caret end
8993

9094
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
9195
let inputVal = e.target.value;

app/src/components/main/Annotation.tsx

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,43 @@ function Annotation({
1212
annotations,
1313
}: Annotations) {
1414
const [state, dispatch] = useContext(StateContext);
15-
const [annotation, setAnnotations] = useState('');
16-
const ref = useRef(null);
15+
const [annotation, setAnnotations] = useState(annotations);
1716
// React hook setting the annotation button modal open/close state
1817
const [open, setOpen] = React.useState(false);
18+
const ref = useRef(null);
19+
// focusIndex and childrenArray are used to find the array of all elements on the canvas
1920
const focusIndex = state.canvasFocus.componentId - 1;
2021
const childrenArray = state.components[focusIndex].children;
21-
22+
2223
// For showing the modal
2324
const handleOpen = (id) => {
24-
const childEle = handleFindAnno(childrenArray, id);
2525
setOpen(true);
2626
};
2727

28-
// For closing the modal
28+
// For closing the modal and setting the global annotation value to the hook value
2929
const handleClose = (id) => {
30-
const focusIndex = state.canvasFocus.componentId - 1;
31-
const childrenArray = state.components[focusIndex].children;
3230
const childEle = handleFindAnno(childrenArray, id);
33-
34-
if(childEle) {
31+
if (childEle) {
32+
// set global annotation value for this component to it's hook value
3533
childEle.annotations = annotation;
3634
}
37-
3835
setOpen(false);
3936
};
4037

4138
/**
4239
* Handles when text exists in the textarea of the modal.
4340
* If text exists/does not exist, corresponding button changes colors.
44-
*/
41+
* Sets hook value to what is contained in the textarea
42+
*/
4543
const handleAnnoChange = (event) => {
4644
const { value } = event.target;
4745

48-
if(value === '' || value === undefined) {
46+
if (value === '' || value === undefined) {
4947
ref.current.style.background = '#3ec1ac';
50-
ref.current.id = 'btn' + event.target.id;
51-
setAnnotations(value);
5248
} else {
5349
ref.current.style.background = '#cc99ff';
54-
ref.current.id = 'btn' + event.target.id;
50+
}
51+
if (value != annotation) {
5552
setAnnotations(value);
5653
}
5754
}
@@ -61,13 +58,18 @@ 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];
67-
}
68-
69-
if(array[i].children.length > 0) {
70-
return handleFindAnno(array[i], id);
61+
for (let i = 0; i < array.length; i++) {
62+
const currentElement = array[i];
63+
if (currentElement.childId === id) {
64+
return currentElement;
65+
// finds nested element if nested within canvas
66+
} else if (currentElement.children.length > 0) {
67+
// temp is to prevent a return of empty string since canvas element should always exist and allows the
68+
// recursion to continue
69+
const temp = handleFindAnno(currentElement.children, id)
70+
if (temp != '') {
71+
return temp;
72+
}
7173
}
7274
}
7375
return '';
@@ -77,28 +79,24 @@ function Annotation({
7779
* This useEffect allows the annotations to remain persistent when changing between root level components on the right panel
7880
*/
7981
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);
82+
const event = {
83+
target: { value: annotation },
84+
id: id,
8885
}
89-
}, [state.canvasFocus])
90-
86+
handleAnnoChange(event);
87+
}, [])
88+
9189
const body = (
9290
<div className='annotate-position'>
9391
<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>
92+
<textarea className='annotate-textarea' id={id.toString()} onChange={handleAnnoChange}>{annotations}</textarea>
9593
</div>
9694
)
9795

9896
return (
99-
<div style={{padding: '1px', float: 'right'}}>
97+
<div style={{ padding: '1px', float: 'right' }}>
10098
<button className='annotate-button-empty' id={"btn" + id} onClick={() => handleOpen(id)} ref={ref}>Notes</button>
101-
<Modal
99+
<Modal
102100
open={open}
103101
onClose={() => handleClose(id)}
104102
keepMounted={true}
@@ -110,4 +108,4 @@ function Annotation({
110108
}
111109

112110
export default Annotation;
113-
// Caret End
111+
// Caret End

app/src/components/main/DemoRender.tsx

Lines changed: 2 additions & 2 deletions
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;
@@ -45,7 +45,7 @@ const DemoRender = (props): JSX.Element => {
4545
useEffect(() => {
4646
const focusIndex = state.canvasFocus.componentId - 1;
4747
const childrenArray = state.components[focusIndex].children;
48-
console.log('Refrenced Children in State!!!', childrenArray);
48+
//console.log('Refrenced Children in State!!!', childrenArray);
4949
const renderedComponents = componentBuilder(childrenArray);
5050
setComponents(renderedComponents);
5151
}, [state.components, state.canvasFocus]);

app/src/components/main/renderDemo.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
.form {
1919
position: relative;
2020
z-index: 1;
21-
background: #FFFFFF;
21+
background: #000000;
2222
max-width: 360px;
2323
margin: 0 auto 100px;
2424
padding: 45px;
@@ -181,9 +181,10 @@
181181
}
182182

183183

184-
/*
185184

186185

186+
/*
187+
187188
List Example
188189
<ul>
189190
<li><span>home</span></li>

app/src/helperFunctions/renderChildren.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import StateContext from '../context/context';
1414
const renderChildren = (children: ChildElement[]) => {
1515
const [state, dispatch] = useContext(StateContext);
1616
return children.map((child: ChildElement, i: number) => {
17-
const { type, typeId, style, childId, children, attributes, name } = child;
17+
const { type, typeId, style, childId, children, attributes, name, annotations} = child;
1818
if (name === '') child.name = state.components[typeId - 1].name;
1919
// A DirectChildComponent is an instance of a top level component
2020
// This component will render IndirectChild components (div/components rendered inside a child component)
@@ -26,7 +26,8 @@ const renderChildren = (children: ChildElement[]) => {
2626
type={type}
2727
typeId={typeId}
2828
key={'DirChildComp' + childId.toString() + name}
29-
name={child.name}
29+
name={name}
30+
annotations={annotations}
3031
/>
3132
);
3233
}
@@ -39,7 +40,8 @@ const renderChildren = (children: ChildElement[]) => {
3940
type={type}
4041
typeId={typeId}
4142
key={'DirChildHTML' + childId.toString() + name}
42-
name={child.name}
43+
name={name}
44+
annotations={annotations}
4345
/>
4446
);
4547
}
@@ -53,7 +55,8 @@ const renderChildren = (children: ChildElement[]) => {
5355
typeId={typeId}
5456
children={children}
5557
key={'DirChildHTMLNest' + childId.toString() + name}
56-
name={child.name}
58+
name={name}
59+
annotations={annotations}
5760
/>
5861
</div>
5962
);
@@ -66,7 +69,7 @@ const renderChildren = (children: ChildElement[]) => {
6669
typeId={typeId}
6770
children={children}
6871
key={'DirChildHTMLNest' + childId.toString() + name}
69-
name={child.name}
72+
name={name}
7073
/>
7174
);
7275
}
@@ -80,7 +83,7 @@ const renderChildren = (children: ChildElement[]) => {
8083
typeId={typeId}
8184
children={children}
8285
key={'RouteLink' + childId.toString() + name}
83-
name={child.name}
86+
name={name}
8487
/>
8588
);
8689
}

0 commit comments

Comments
 (0)