Skip to content

Commit 595176e

Browse files
cleaned up a few pseudocoded files. Finished pseudocoding Action, RouteDescription, SwitchApp, ActionContainer, and ErrorContainer
1 parent 903f828 commit 595176e

File tree

8 files changed

+113
-23
lines changed

8 files changed

+113
-23
lines changed

src/app/components/Action.tsx

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import ReactHover, { Trigger, Hover } from 'react-hover';
77
import { changeView, changeSlider } from '../actions/actions';
88
import { ActionProps, OptionsCursorTrueWithMargin } from '../FrontendTypes';
99

10+
/*
11+
This render's the individual snapshot components on the left side column
12+
*/
13+
1014
/**
1115
* @function Action
1216
* @param selected : The selected action in the array of state changes
@@ -21,9 +25,9 @@ import { ActionProps, OptionsCursorTrueWithMargin } from '../FrontendTypes';
2125
* @method handleOnkeyDown Executes key commands
2226
*
2327
*/
24-
// index and delta props were removed from Action.jsx */
25-
// viewIndex and handleonkeyDown added to props
28+
2629
const Action = (props: ActionProps): JSX.Element => {
30+
// We destructure the 'props' that were passed into this component
2731
const {
2832
selected,
2933
last,
@@ -41,34 +45,61 @@ const Action = (props: ActionProps): JSX.Element => {
4145
* @function cleanTime: Displays render times for state changes
4246
* @returns render display time in seconds in milliseconds
4347
*/
44-
const cleanTime = (): string => {
48+
49+
50+
const cleanTime = (): string => {
51+
// if there is no 'componentData' or 'componentData.actualDuration' return "NO TIME"
4552
if (!componentData || !componentData.actualDuration) {
4653
return 'NO TIME';
4754
}
55+
56+
// seconds is undefined but can take a number or a string
4857
let seconds: number | string;
58+
// milliseconds is of any type and taken from the 'componentData.actualDuration'
4959
let milliseconds: any = componentData.actualDuration;
60+
61+
// if the milliseconds is greater than 60
5062
if (Math.floor(componentData.actualDuration) > 60) {
63+
// we divide our milliseconds by 60 to determine our seconds
5164
seconds = Math.floor(componentData.actualDuration / 60);
65+
// and we convert our seconds into a string
5266
seconds = JSON.stringify(seconds);
67+
// if the seconds string is only a single digit
5368
if (seconds.length < 2) {
69+
// we can add a 0 in front of it so that if 'seconds = "1"' it will come out as 'seconds = "01"'
5470
seconds = '0'.concat(seconds);
5571
}
72+
// Our true milliseconds then becomes the remainder of dividing our initial milliseconds by 60
5673
milliseconds = Math.floor(componentData.actualDuration % 60);
5774
} else {
75+
// if we haven't even reached one second yet, our seconds are 00
5876
seconds = '00';
5977
}
78+
79+
// we convert our milliseconds string into a floating point number that has up to two decimal places.
6080
milliseconds = Number.parseFloat(milliseconds as string).toFixed(2);
81+
82+
// we split our milliseconds using the decimal and come out with an array of two numbers
6183
const arrayMilliseconds: string | number = milliseconds.split('.');
84+
85+
// if our millisecond string only has one digit
6286
if (arrayMilliseconds[0].length < 2) {
87+
// we add a 0 in front of it so that in the a sample number of '1' becomes '01'
6388
arrayMilliseconds[0] = '0'.concat(arrayMilliseconds[0]);
6489
}
90+
// if this is the initial snapshot
6591
if (index === 0) {
92+
// we give it a timestamp
6693
return `${seconds}:${arrayMilliseconds[0]}.${arrayMilliseconds[1]}`;
6794
}
95+
// if these are succeeding snapshots, we add a '+' to the timestamp
6896
return `+${seconds}:${arrayMilliseconds[0]}.${arrayMilliseconds[1]}`;
6997
};
98+
99+
// we run cleanTime on the creation of this component so that we can get the timestamp
70100
const displayTime: string = cleanTime();
71101

102+
// creates an options object that 'ReactHover' component will use to modify it's behaviour
72103
const optionsCursorTrueWithMargin: OptionsCursorTrueWithMargin = {
73104
followCursor: true,
74105
shiftX: 20,

src/app/components/RouteDescription.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import React from 'react';
22

3+
/*
4+
Render's the red route description on app's left sided column between the clear button and the list of state snapshots. The route description is derived from the first state snapshot.
5+
*/
6+
37
type RouteProps = {
48
actions: JSX.Element[];
59
};
610

711
const RouteDescription = (props: RouteProps): JSX.Element => {
8-
// Use new URL to use the url.pathname method.
912
const { actions } = props;
13+
// Use new URL to use the url.pathname method.
1014
const url: URL = new URL(actions[0].props.routePath);
1115
return (
1216
<div className='routedescription'>

src/app/components/SwitchApp.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,37 @@ import Select from 'react-select';
33
import { useStoreContext } from '../store';
44
import { setTab } from '../actions/actions';
55

6+
/*
7+
This is the dropdown menu on the left column above the 'clear' button and the state snapshots list. It allows us to switch between which website/application we are currently working on.
8+
9+
Currently, it doesn't seem to be fully implemented since switching applications doesn't change to snapshots that are relevant into the newly selected application
10+
*/
11+
612
const SwitchAppDropdown = (): JSX.Element => {
13+
// we destructure the returned context object from the invocation of the useStoreContext function. Properties not found on the initialState object (dispatch) are from the useReducer function invocation in the App component
714
const [{ currentTab, tabs }, dispatch] = useStoreContext();
8-
15+
// tabsArray is an empty array that will take objects as it's elements
916
const tabsArray: {}[] = [];
17+
18+
// We populate our 'tabsArray' with objects derived from the 'tab' that is currently being iterated on.
1019
Object.keys(tabs).forEach((tab) => {
1120
tabsArray.unshift({ value: tab, label: tabs[tab].title });
1221
});
1322

23+
// we create a 'currTab' object and populate it's values from the 'currentTab' that was destructured from our context object
1424
const currTab: {} = {
1525
value: currentTab,
1626
label: tabs[currentTab].title,
1727
};
1828

1929
const customStyles: {} = {
30+
// we define a menu method that takes in two parameters
2031
menu: (provided, state):{} => {
32+
// why does this ternary even matter if the end result is the same?
2133
const outline: string = state.isSelected ? 'transparent' : 'transparent';
2234
const margin: number = 0;
2335

36+
// we return an object that adds the ouline and margin to the provided object
2437
return { ...provided, outline, margin };
2538
},
2639
};

src/app/containers/ActionContainer.tsx

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { useStoreContext } from '../store';
1010
import RouteDescription from '../components/RouteDescription';
1111
import { Obj } from '../FrontendTypes';
1212

13+
/*
14+
This file renders the 'ActionContainer'. The action container is the leftmost column in the application. It includes the button that shrinks and expands the action container, a dropdown to select the active site, a clear button, the current selected Route, and a list of selectable snapshots with timestamps.
15+
*/
1316

1417
// resetSlider locates the rc-slider elements on the document and resets it's style attributes
1518
const resetSlider = () => {
@@ -40,18 +43,36 @@ function ActionContainer(props): JSX.Element {
4043
// we create an array 'hierarchyArr' that will hold objects and numbers
4144
const hierarchyArr: (number | {})[] = [];
4245

43-
// function to traverse state from hierarchy and also getting information on display name and component name
46+
/*
47+
48+
function to traverse state from hierarchy and also getting information on display name and component name
49+
50+
the obj parameter is an object with the following structure:
51+
{
52+
stateSnapshot: {
53+
route: any;
54+
children: any[];
55+
};
56+
name: number;
57+
branch: number;
58+
index: number;
59+
children?: [];
60+
}
61+
62+
*/
63+
4464
const displayArray = (obj: Obj): void => {
4565
if (
46-
// if the stateSnapshot has a non-empty children array
66+
// if the 'stateSnapshot' has a non-empty 'children' array
4767
obj.stateSnapshot.children.length > 0 &&
4868
// and there is an element
4969
obj.stateSnapshot.children[0] &&
50-
// with a state
70+
// with a 'state'
5171
obj.stateSnapshot.children[0].state &&
52-
// and a name
72+
// and a 'name'
5373
obj.stateSnapshot.children[0].name
5474
) {
75+
// we create a new Record object (whose property keys are Keys and whose property values are Type. This utility can be used to map the properties of a type to another type) and populate it's properties with relevant values from our argument 'obj'.
5576
const newObj: Record<string, unknown> = {
5677
index: obj.index,
5778
displayName: `${obj.name}.${obj.branch}`,
@@ -63,20 +84,23 @@ function ActionContainer(props): JSX.Element {
6384
? ''
6485
: obj.stateSnapshot.children[0].componentData,
6586
};
87+
// we push our record object into 'hiearchyArr' defined on line 41
6688
hierarchyArr.push(newObj);
6789
}
90+
// if argument has a 'children' array, we iterate through it and run 'displayArray' on each element
6891
if (obj.children) {
6992
obj.children.forEach((element): void => {
7093
displayArray(element);
7194
});
7295
}
7396
};
97+
7498
// the hierarchy gets set on the first click in the page
7599
// when page in refreshed we may not have a hierarchy so we need to check if hierarchy was initialized
76100
// if true invoke displayArray to display the hierarchy
77101
if (hierarchy) displayArray(hierarchy);
78102

79-
// handles keyboard presses, function passes an event and index of each action-component
103+
// This function allows us to use our arrow keys to jump between snapshots. It passes an event and the index of each action-component. Using the arrow keys allows us to highligh snapshots and the enter key jumps to the selected snapshot
80104
function handleOnKeyDown(e: KeyboardEvent, i: number): void {
81105
let currIndex = i;
82106
// up arrow key pressed
@@ -93,15 +117,16 @@ function ActionContainer(props): JSX.Element {
93117
}
94118
// enter key pressed
95119
else if (e.key === 'Enter') {
96-
e.stopPropagation();
120+
e.stopPropagation(); // prevents further propagation of the current event in the capturing and bubbling phases
97121
e.preventDefault(); // needed or will trigger onClick right after
98122
dispatch(changeSlider(currIndex));
99123
}
100124
}
101-
// Sort by index.
102125

126+
// Sort hierarchyArr by index property of each object. This will be useful when later when we build our components so that our components will be displayed in index/chronological order
103127
hierarchyArr.sort((a:Obj, b:Obj):number => a.index - b.index);
104128

129+
// we create a map of components that are constructed from "hierarchyArr's" elements/snapshots
105130
actionsArr = hierarchyArr.map(
106131
(snapshot: {
107132
routePath: any;
@@ -111,9 +136,18 @@ function ActionContainer(props): JSX.Element {
111136
componentName: string;
112137
componentData: { actualDuration: number } | undefined;
113138
}) => {
139+
// destructure index from snapshot
114140
const { index } = snapshot;
141+
// boolean on whether the current index is the same as the viewIndex
115142
const selected = index === viewIndex;
143+
// boolean on whether the view index is less than 0 and if the index is the same as the last snapshot's index value in hierarchyArr
116144
const last = viewIndex === -1 && index === hierarchyArr.length - 1;
145+
/*
146+
====================================================
147+
// boolean
148+
// Not sure what currLocation is at this time
149+
====================================================
150+
*/
117151
const isCurrIndex = index === currLocation.index;
118152
return (
119153
<Action
@@ -137,6 +171,7 @@ function ActionContainer(props): JSX.Element {
137171
);
138172
useEffect(() => {
139173
setActionView(true);
174+
// !!!! Why is the dependency array the function being called within the useEffect? !!!!
140175
}, [setActionView]);
141176

142177
// Function sends message to background.js which sends message to the content script
@@ -155,7 +190,9 @@ function ActionContainer(props): JSX.Element {
155190
};
156191

157192
const routes: {} = {};
193+
// iterate through our actionsArr
158194
for (let i = 0; i < actionsArr.length; i += 1) {
195+
// if 'routes' doesn't have a property key that is the same as the current component at index[i] routePath we create an array with the first element being the component at index [i]. If it does exist, we push the component at index [i] to the apporpriate routes[routePath]
159196
if (!routes.hasOwnProperty(actionsArr[i].props.routePath)) {
160197
routes[actionsArr[i].props.routePath] = [actionsArr[i]];
161198
} else {

src/app/containers/ErrorContainer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ function ErrorContainer(): JSX.Element {
6464
setLoadingArray(1, true);
6565
setLoadingArray(2, true);
6666

67+
// if there is a current timeout set, we clear it
6768
if (timeout.current) {
6869
clearTimeout(timeout.current);
6970
timeout.current = null;
7071
}
7172
}
7273

74+
// We check our status object and see if contentScriptLaunched is false
7375
// if content script hasnt been found, set timer or immediately resolve
74-
// check our status object and see if contentScriptLaunched is false
7576
if (!status.contentScriptLaunched) {
7677
// if contentScriptLaunched is false, we check our loadingArray state at position [0]
7778
if (loadingArray[0] === true) {

src/app/containers/MainContainer.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ import {
1717
} from '../actions/actions';
1818
import { useStoreContext } from '../store';
1919

20+
/*
21+
This is the main container where everything in our application is rendered
22+
*/
23+
2024
function MainContainer(): JSX.Element {
2125
// we destructure the returned context object from the invocation of the useStoreContext function. Properties not found on the initialState object (store/dispatch) are from the useReducer function invocation in the App component
2226
const [store, dispatch] = useStoreContext();
23-
// we continue to destructure store and get the tabs/currentTab/port
27+
// we continue to destructure 'store' and get the tabs/currentTab/port
2428
const { tabs, currentTab, port } = store;
25-
// We create a local state actionView and set it to true
29+
// We create a local state 'actionView' and set it to true
2630
const [actionView, setActionView] = useState(true);
2731

2832
// this function handles Time Jump sidebar view
@@ -35,10 +39,8 @@ function MainContainer(): JSX.Element {
3539
// toggles the addition or the removal of the 'no-aside' class
3640
toggleElem.classList.toggle('no-aside');
3741

38-
// hides the record toggle button from Actions Container in Time Jump sidebar view
3942
const recordBtn = document.getElementById('recordBtn');
40-
41-
// switches whether to display the button by changing the display property between none and flex
43+
// switches whether to display the record toggle button by changing the display property between none and flex
4244
if (recordBtn.style.display === 'none') {
4345
recordBtn.style.display = 'flex';
4446
} else {
@@ -51,7 +53,7 @@ function MainContainer(): JSX.Element {
5153
if (port) return;
5254

5355
// chrome.runtime allows our application to retrieve our service worker (our eventual bundles/background.bundle.js after running npm run build), details about the manifest, and allows us to listen and respond to events in our application lifecycle.
54-
// we connect our listeners to our service worker
56+
// we connect to our service worker
5557
const currentPort = chrome.runtime.connect();
5658

5759
// listen for a message containing snapshots from the background script
@@ -72,7 +74,7 @@ function MainContainer(): JSX.Element {
7274
const tabsArray: Array<string> = Object.keys(payload);
7375
// we then map out our tabsArray where we convert each string into a number
7476
const numTabsArray: number[] = tabsArray.map((tab) => Number(tab));
75-
// we then get the number of tabs we have
77+
// we then get the largest tab number value
7678
maxTab = Math.max(...numTabsArray);
7779
}
7880

@@ -120,7 +122,7 @@ function MainContainer(): JSX.Element {
120122
// assign port to state so it could be used by other components
121123
dispatch(setPort(currentPort));
122124

123-
// NOTE: There is no dependency array declared here.
125+
// !!!!! NOTE: There is no dependency array declared here. This may result in an infinite loop. Needs more investigation !!!!!
124126
});
125127

126128
// Error Page launch IF(Content script not launched OR RDT not installed OR Target not React app)

src/app/store.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ import React, { useContext } from 'react';
55
export const StoreContext = React.createContext();
66

77
// the useStoreContext function allows us to use use the above declared StoreContext.
8-
export const useStoreContext = () => useContext(StoreContext);
8+
export const useStoreContext = () => useContext(StoreContext);

src/backend/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
* @function linkFiber
44
*/
55
// --------------------------START OF IMPORT------------------------------------
6-
// regenerator runtime supports async functionality
6+
// regenerator runtime supports async functionality : This package implements a fully-functional source transformation that takes the syntax for generators/yield from ECMAScript 2015 or ES2015 and Asynchronous Iteration proposal and spits out efficient JS-of-today (ES5) that behaves the same way.
77
import 'regenerator-runtime/runtime';
8+
// linkFiberInitialization (actually uses the function linkFiber but is labeled here as linkFiberInitialization, returns a function). When this returned function is invoked, it checks if devTools is installed, checks if the website is a reactApp, adds event listeners for timetravel, and allows us to obtain the initial FiberRoot Node from react dev tool
89
import linkFiberInitialization from './routers/linkFiber';
10+
// timeJumpInitialization (actually uses the function timeJumpInitiation but is labeled here as linkFiberInitialization, returns a function) returns a function that sets jumping to false and handles timetravel feature
911
import timeJumpInitialization from './controllers/timeJump';
1012
import { Snapshot, Status, MsgData } from './types/backendTypes';
1113
import routes from './models/routes';

0 commit comments

Comments
 (0)