Skip to content

Commit c212410

Browse files
CODE.IOCODE.IO
authored andcommitted
added comments to ApplicationContext for following data flow
1 parent 893fb58 commit c212410

File tree

5 files changed

+42
-3
lines changed

5 files changed

+42
-3
lines changed

app/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import './stylesheets/scrollBar.scss';
55

66

77
// this is the fitness gram pacer test
8+
// React memo helps with rendering optimization. The components within React memo will only be rerendered if prompt has changed
89
const App: React.FC = React.memo(() => {
910
return (
1011
<div>

app/components/Splash.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState, useEffect } from 'react';
22
import '../stylesheets/Splash.scss';
33

4+
//Chronos logo when first starting the electron app. Has the picture for 4 seconds.
45
const Splash: React.FC = React.memo(props => {
56
const [visible, setVisible] = useState(true);
67

app/containers/DashboardContainer.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,22 @@ import AwsContextProvider from '../context/AwsContext';
1313
import '../stylesheets/Dashboard.scss';
1414

1515
const DashboardContainer = React.memo(() => {
16+
1617
const [visible, setVisible] = useState(false);
1718

19+
/**
20+
* When DashBoard Container first mounted, visible is default to false, so that the Splash component can be stay visible.
21+
* After 4 seconds, set the DashBoard Container visibility to true
22+
*/
1823
useEffect(() => {
1924
setTimeout(() => setVisible(true), 4000);
2025
}, []);
2126

27+
/**
28+
* 1. Provide access to use ReactRouter
29+
* 2. Provide access to serveral Context Providers (a.k.a Data Bank), including Application, Dashboard, Comms, Docker, Health, Event, Query, Aws
30+
* 3. Child Component: SidebarContainer and MainContainer
31+
*/
2232
return (
2333
<>
2434
{visible && (

app/containers/SidebarContainer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { ApplicationContext } from '../context/ApplicationContext';
1111
import { AwsContext } from '../context/AwsContext';
1212

1313
const SidebarContainer = React.memo(props => {
14-
const { intervalID } = useContext(ApplicationContext);
14+
15+
const { intervalID } = useContext (ApplicationContext);
1516
const { isLoading, setLoadingState } = useContext(AwsContext);
1617

1718
// clear interval and set loading state to true when leaving graph containers

app/context/ApplicationContext.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,13 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
2424
const [savedMetrics, setSavedMetrics] = useState({});
2525
const [appIndex, setAppIndex] = useState<number>(0);
2626
const [intervalID, setIntervalID] = useState<NodeJS.Timeout | null>(null);
27-
28-
function tryParseJSON(jsonString: any) {
27+
28+
/**
29+
* @function tryParseJson - a function that will parse the JSON data into an object. If there is any error during parsing (a.k.a there is a circular inside the JSON data), console log the error
30+
* @param jsonString - JSON data that is received from backend
31+
* @return an object with all information from backend
32+
*/
33+
function tryParseJSON(jsonString: string) {
2934
try {
3035
const o = JSON.parse(jsonString);
3136

@@ -38,6 +43,17 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
3843
return false;
3944
}
4045

46+
/**
47+
* @function fetchServicesNames - a function that will take an application name and update the state of `serviceData` based on backend response
48+
* 1. Take in an application name
49+
*
50+
* 2. Send a `servicesRequest` to backend
51+
*
52+
* 3. Upon `servicesResponse`, parse the received JSON data and assign it to `servicesData`
53+
*
54+
* 4. Remove the listener for `servicesResponse`
55+
* @param application - application name
56+
*/
4157
const fetchServicesNames = useCallback((application: string) => {
4258
console.log('app when fetch services name', application);
4359
// setApp(application);
@@ -46,13 +62,20 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
4662

4763
ipcRenderer.on('servicesResponse', (event: Electron.Event, data: any) => {
4864
let result: any;
65+
// Parse JSON data into object
4966
if (tryParseJSON(data)) result = JSON.parse(data);
5067
console.log('result from ipcrenderer services response is: ', result);
5168
setServicesData(result);
5269
ipcRenderer.removeAllListeners('servicesResponse');
5370
});
5471
}, []);
5572

73+
/**
74+
* @function connectToDB - a function that ensure database is connected with passed-in `username` and `index`. After that, invoke `fetchServicesName`, passing in `application`
75+
* @param username -
76+
* @param index -
77+
* @param application - application name
78+
*/
5679
const connectToDB = useCallback((username: string, index: number, application: string) => {
5780
ipcRenderer.removeAllListeners('databaseConnected');
5881
ipcRenderer.send('connect', username, index);
@@ -62,6 +85,9 @@ const ApplicationContextProvider: React.FC<AppContextProps> = React.memo(props =
6285
});
6386
}, []);
6487

88+
/**
89+
* @function getSavedMetrics - a function that will wait for backend `savedMetricsResponse` to update metrics using `setSavedMetrics`
90+
*/
6591
const getSavedMetrics = useCallback(() => {
6692
ipcRenderer.send('savedMetricsRequest');
6793
ipcRenderer.on('savedMetricsResponse', (event: Electron.Event, data: any) => {

0 commit comments

Comments
 (0)