@@ -4,7 +4,7 @@ import Modal from '@material-ui/core/Modal';
4
4
import StateContext from '../../context/context' ;
5
5
6
6
function Annotation ( { id, name, annotations } : Annotations ) {
7
- const [ state ] = useContext ( StateContext ) ;
7
+ const [ state , dispatch ] = useContext ( StateContext ) ;
8
8
// const [annotation, setAnnotations] = useState(annotations);
9
9
// React hook setting the annotation button modal open/close state
10
10
// const [open, setOpen] = React.useState(false);
@@ -16,40 +16,42 @@ function Annotation({ id, name, annotations }: Annotations) {
16
16
17
17
// ---------------------------------------------- NEW CODE for DELETE BUTTONS (start) ---------------------------------------
18
18
const deleteHTMLtype = ( id : number ) => {
19
- console . log ( id , childrenArray ) ;
20
- let arrIndex : number = - 1 ;
19
+ dispatch ( {
20
+ type : 'DELETE CHILD' ,
21
+ payload : { id }
22
+ } ) ;
21
23
22
- let arrOfAllChildIDs : number [ ] = [ ] ;
23
- recurseAllChildren ( childrenArray ) ;
24
-
25
- function recurseAllChildren ( childArray ) {
26
- // console.log('Full Array: ', childArray, arrOfAllChildIDs);
27
- for ( let index in childArray ) {
28
- // console.log( index);
29
-
30
- if ( childArray [ index ] . children . length ) {
31
- // console.log('In Recurse - non-endpoint: ', childArray[index].childId);
32
- arrOfAllChildIDs . push ( childArray [ index ] . childId ) ; // Use this only to pull all non-endpoint childIds, document out breaks
33
- if ( childArray [ index ] . childId === id ) {
34
- arrIndex = Number ( index ) ;
35
- // Remove BOTH element & preceding separator spacing objects from array if NOT nested
36
- childArray . splice ( arrIndex - 1 , 2 ) ;
37
- break ;
38
- }
39
- recurseAllChildren ( childArray [ index ] . children ) ;
40
- } else if ( childArray [ index ] . childId < 1000 )
41
- // FILTER OUT separators...
42
- // console.log('In Recurse - endpoint: ', childArray[index].childId);
43
- arrOfAllChildIDs . push ( childArray [ index ] . childId ) ; // Use this only to pull all endpoint childIds, document out breaks
44
- if ( childArray [ index ] . childId === id ) {
45
- arrIndex = Number ( index ) ;
46
- // Remove BOTH element & preceding separator spacing objects from array if NOT nested
47
- childArray . splice ( arrIndex - 1 , 2 ) ;
48
- // console.log(index, arrIndex, 'ultimate', childArray[index]);
49
- break ;
50
- }
51
- }
52
- }
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
+ // }
53
55
// console.log(arrIndex);
54
56
// console.log('arrOfAllChildIDs: ', arrOfAllChildIDs);
55
57
} ;
0 commit comments