@@ -34,6 +34,7 @@ interface HealthDataObject {
3434const HealthContextProvider : React . FC < Props > = React . memo ( ( { children } ) => {
3535 const [ healthData , setHealthData ] = useState < any > ( { healthDataList : [ ] , healthTimeList : [ ] } ) ;
3636 const [ services , setServices ] = useState < Array < string > > ( [ ] ) ;
37+ console . log ( { services} )
3738
3839 function tryParseJSON ( jsonString : any ) {
3940 try {
@@ -55,46 +56,46 @@ const HealthContextProvider: React.FC<Props> = React.memo(({ children }) => {
5556 */
5657
5758 const fetchHealthData = useCallback ( async servers => {
58- ipcRenderer . removeAllListeners ( 'healthResponse' ) ;
59+ // ipcRenderer.removeAllListeners('healthResponse');
5960
6061 let temp : HealthDataObject [ ] = [ ] ;
6162 await Promise . all ( servers . map ( async ( service : string ) => {
62- //NOT WORKING HERE
63+ ipcRenderer . removeAllListeners ( 'healthResponse' ) ;
64+
6365 try {
6466 const newPromise : any = await new Promise ( ( resolve , reject ) => {
6567 ipcRenderer . send ( 'healthRequest' , `${ service } ` ) ;
6668 ipcRenderer . on ( 'healthResponse' , ( event : Electron . Event , data : string ) => {
67- let result : object [ ] ;
68- // console.log({data})
69- if ( JSON . stringify ( data ) !== '{}' && tryParseJSON ( data ) ) {
70- result = JSON . parse ( data ) ;
71- // console.log({result})
72- // console.log('HealthContext.tsx line 68 result: ', result, 'service', service, 'Obj key', Object.keys(result[0])[0]);
69+ //V14: the line does not appear necessary, leaving it here commented out in case another group runs into a problem
70+ // if (JSON.stringify(data) !== '{}' && tryParseJSON(data)) {
71+ const response = JSON . parse ( data ) ;
72+ // console.log({response})
73+ const [ dbName ] = Object . keys ( response [ 0 ] )
7374 //result exists, has a length prop, and the service name and database name are same
74- if ( result && result . length && `${ service } ` === Object . keys ( result [ 0 ] ) [ 0 ] ) {
75- resolve ( result [ 0 ] ) ;
75+ console . log ( { service, dbName} )
76+ //V14: this block is needed here because of unecessary calls for each service
77+ //a prior group was getting the dbName from the response object and since objects dont remember
78+ //insertion order they are running all the calls for each service in the array
79+ if ( response && response . length && `${ service } ` === dbName ) {
80+ resolve ( response [ 0 ] ) ;
7681 }
77- }
82+ // }
7883 } ) ;
7984 } )
8085 temp . push ( newPromise ) ;
81- // console.log('HealthContext.tsx line 80 temp populates?: ', temp, serv)
8286 if ( checkServicesComplete ( temp , [ `${ service } ` ] ) ) {
87+ console . log ( { temp} )
88+
8389 setServices ( [ `${ service } ` ] ) ;
8490 let transformedData : any = { } ;
85- // console.log('original healthData before transformation: ', temp);
86- // transformedData = {
87- // healthDataList: [1,2,3,4,5],
88- // healthTimeList: [1,2,3,4,5]
89- // } //testing typescript, transformedDATA of type 2 arrays with basic entries?
9091 transformedData = healthTransformer ( temp ) ; //must match the setHealthData STATE format
91- // console.log('healthData after tranformation: ', transformedData);
9292 setHealthData ( transformedData ) ;
9393 }
9494 } catch ( err ) {
95- // console.log("healthcontext.tsx ERROR: ", err);
95+ console . log ( "healthcontext.tsx ERROR: " , err ) ;
9696 } ;
9797 }
98+
9899 ) )
99100 } , [ ] ) ;
100101
@@ -104,9 +105,9 @@ const HealthContextProvider: React.FC<Props> = React.memo(({ children }) => {
104105 }
105106 const arr1 : string [ ] = [ ] ;
106107 for ( let i = 0 ; i < temp . length ; i ++ ) {
107- arr1 . push ( Object . keys ( temp [ i ] ) [ 0 ] ) ;
108+ const [ serviceName ] = Object . keys ( temp [ i ] )
109+ arr1 . push ( serviceName ) ;
108110 }
109- // console.log('in checkServicesComplete line 139: ', arr1);
110111 return arr1 . sort ( ) . toString ( ) === servers . sort ( ) . toString ( ) ;
111112 } ;
112113
0 commit comments