@@ -5,154 +5,25 @@ import StateContext from '../../context/context';
5
5
6
6
function Annotation ( { id, name, annotations } : Annotations ) {
7
7
const [ state , dispatch ] = useContext ( StateContext ) ;
8
- // const [annotation, setAnnotations] = useState(annotations);
9
- // React hook setting the annotation button modal open/close state
10
- // const [open, setOpen] = React.useState(false);
11
- // const ref = useRef(null);
12
8
13
- // focusIndex and childrenArray are used to find the array of all elements on the canvas
14
- const focusIndex = state . canvasFocus . componentId - 1 ;
15
- const childrenArray = state . components [ focusIndex ] . children ; // ADDING SLICE HERE CAUSES STATE to NOT CHANGE...
9
+ // -------------------------------- NEW CODE for DELETE BUTTONS, REPLACING ANNOTATIONS ---------------------------------------
16
10
17
- // ---------------------------------------------- NEW CODE for DELETE BUTTONS (start) ---------------------------------------
18
11
const deleteHTMLtype = ( id : number ) => {
19
12
dispatch ( {
20
13
type : 'DELETE CHILD' ,
21
14
payload : { id }
22
15
} ) ;
23
-
24
- // console.log(id, childrenArray);
25
- // let arrIndex: number = -1;
26
- // let arrOfAllChildIDs: number[] = [];
27
- // recurseAllChildren(childrenArray);
28
- // function recurseAllChildren(childArray) {
29
- // // console.log('Full Array: ', childArray, arrOfAllChildIDs);
30
- // for (let index in childArray) {
31
- // // console.log(index);
32
- // if (childArray[index].children.length) {
33
- // // console.log('In Recurse - non-endpoint: ', childArray[index].childId);
34
- // arrOfAllChildIDs.push(childArray[index].childId); // Use this only to pull all non-endpoint childIds, document out breaks
35
- // if (childArray[index].childId === id) {
36
- // arrIndex = Number(index);
37
- // // Remove BOTH element & preceding separator spacing objects from array if NOT nested
38
- // childArray.splice(arrIndex - 1, 2);
39
- // break;
40
- // }
41
- // recurseAllChildren(childArray[index].children);
42
- // } else if (childArray[index].childId < 1000)
43
- // // FILTER OUT separators...
44
- // // console.log('In Recurse - endpoint: ', childArray[index].childId);
45
- // arrOfAllChildIDs.push(childArray[index].childId); // Use this only to pull all endpoint childIds, document out breaks
46
- // if (childArray[index].childId === id) {
47
- // arrIndex = Number(index);
48
- // // Remove BOTH element & preceding separator spacing objects from array if NOT nested
49
- // childArray.splice(arrIndex - 1, 2);
50
- // // console.log(index, arrIndex, 'ultimate', childArray[index]);
51
- // break;
52
- // }
53
- // }
54
- // }
55
- // console.log(arrIndex);
56
- // console.log('arrOfAllChildIDs: ', arrOfAllChildIDs);
57
16
} ;
58
- // ---------------------------------------------- NEW CODE for DELETE BUTTONS (end) ---------------------------------------
59
-
60
- // ---------------------------------------------- LEGACY CODE (start) ---------------------------------------
61
- // // For showing the modal
62
- // const handleOpen = () => {
63
- // setOpen(true);
64
- // };
65
- // // For closing the modal and setting the global annotation value to the hook value
66
- // const handleClose = (id) => {
67
- // const childEle = handleFindAnno(childrenArray, id);
68
- // if (childEle) {
69
- // // set global annotation value for this component to it's hook value
70
- // childEle.annotations = annotation;
71
- // }
72
- // setOpen(false);
73
- // };
74
- // /**
75
- // * Handles when text exists in the textarea of the modal.
76
- // * If text exists/does not exist, corresponding button changes colors.
77
- // * Sets hook value to what is contained in the textarea
78
- // */
79
- // const handleAnnoChange = (event) => {
80
- // const { value } = event.target;
81
- // if (value === '' || value === undefined) {
82
- // ref.current.style.background = '#0CD34C';
83
- // } else {
84
- // ref.current.style.background = '#D59DFF';
85
- // }
86
- // if (value != annotation) {
87
- // setAnnotations(value);
88
- // }
89
- // };
90
- // /**
91
- // * This handler will find the specific anno for the corresponding component on the canvas in the childrenArray -
92
- // * where the canvas components are placed
93
- // */
94
- // const handleFindAnno = (array, id) => {
95
- // for (let i = 0; i < array.length; i++) {
96
- // const currentElement = array[i];
97
- // if (currentElement.childId === id) {
98
- // return currentElement;
99
- // // finds nested element if nested within canvas
100
- // } else if (currentElement.children.length > 0) {
101
- // // temp is to prevent a return of empty string since canvas element should always exist and allows the
102
- // // recursion to continue
103
- // const temp = handleFindAnno(currentElement.children, id);
104
- // if (temp != '') {
105
- // return temp;
106
- // }
107
- // }
108
- // }
109
- // return '';
110
- // };
111
- // /**
112
- // * This useEffect allows the annotations to remain persistent when changing between root level components on the right panel
113
- // */
114
- // useEffect(() => {
115
- // const event = {
116
- // target: { value: annotation },
117
- // id: id
118
- // };
119
- // handleAnnoChange(event);
120
- // }, []);
121
-
122
- // const body = (
123
- // <div className="annotate-position">
124
- // <span className="annotate-textarea-header">
125
- // {' '}
126
- // Notes for: {name} ( {id} )
127
- // </span>
128
- // <textarea
129
- // className="annotate-textarea"
130
- // id={id.toString()}
131
- // onChange={handleAnnoChange}
132
- // >
133
- // {annotations}
134
- // </textarea>
135
- // </div>
136
- // );
137
- // ---------------------------------------------- LEGACY CODE (end) ---------------------------------------
138
17
139
18
return (
140
19
< div style = { { padding : '1px' , float : 'right' } } >
141
20
< button
142
- className = "annotate-button-empty" // NOTE: This class name no longer accurate
21
+ className = "annotate-button-empty" // NOTE: This className no longer accurate --> to update to delete button, same w/ Annotation export throughout
143
22
id = { 'btn' + id }
144
23
onClick = { ( ) => deleteHTMLtype ( id ) }
145
- // ref={ref}
146
24
>
147
25
x
148
26
</ button >
149
- { /* <Modal
150
- open={open}
151
- onClose={() => handleClose(id)}
152
- keepMounted={true}
153
- >
154
- {body}
155
- </Modal> */ }
156
27
</ div >
157
28
) ;
158
29
}
0 commit comments