Skip to content

Commit e9c1d86

Browse files
Finished TravelContainer, MainSlider. Adjusted old pseudocode to be more in-line
1 parent 5dad326 commit e9c1d86

File tree

8 files changed

+124
-189
lines changed

8 files changed

+124
-189
lines changed

src/app/components/App.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ const initialState: InitialStateProps = {
2020

2121
function App(): JSX.Element {
2222
return (
23-
// we wrap our application with the <Router> tag so that all components that are nested will have the react-router context
24-
<Router>
25-
{/* we wrap our MainContainer with the provider so that we will be able to use the store context. We create our store by using useReducer and passing it into the value property */}
26-
<StoreContext.Provider value={useReducer(mainReducer, initialState)}>
23+
<Router> {/* we wrap our application with the <Router> tag so that all components that are nested will have the react-router context */}
24+
<StoreContext.Provider value={useReducer(mainReducer, initialState)}> {/* we wrap our MainContainer with the provider so that we will be able to use the store context. We create our store by using useReducer and passing it into the value property */}
2725
<MainContainer />
2826
</StoreContext.Provider>
2927
</Router>

src/app/components/ErrorMsg.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ function parseError(loadingArray: [], status: Record<string, unknown>): string {
1616
loadingArray.forEach((e) => {
1717
if (e === false) stillLoading = false;
1818
});
19-
// As long as everything is still loading dont diplay an error message
20-
if (stillLoading) return 'default';
19+
20+
if (stillLoading) return 'default'; // As long as everything is still loading dont diplay an error message
2121

2222
// If we're done loading everything, return the first status that fails
2323
if (!status.contentScriptLaunched) return 'Content Script Error';
@@ -27,8 +27,7 @@ function parseError(loadingArray: [], status: Record<string, unknown>): string {
2727
}
2828

2929
function ErrorMsg({ loadingArray, status, launchContent }): JSX.Element {
30-
// we use the evaluated result (string) of 'parseError' and match it to the case so that an appropriate error message will be displayed to the user
31-
switch (parseError(loadingArray, status)) {
30+
switch (parseError(loadingArray, status)) { // parseError returns a string based on the loadingArray and status. The returned string is matched to a case so that an appropriate error message will be displayed to the user
3231
case 'Content Script Error':
3332
return (
3433
<div>

src/app/components/Loader.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,18 @@ This file is what decides what icon (loading, checkmark, exclamation point) is d
1515

1616
const handleResult = (result: boolean): JSX.Element =>
1717
result ? (
18-
// if result boolean is true, we display a checkmark icon
19-
<FontAwesomeIcon icon={faCheck} className='check' size='lg' />
18+
<FontAwesomeIcon icon={faCheck} className='check' size='lg' /> // if result boolean is true, we display a checkmark icon
2019
) : (
21-
// if the result boolean is false, we display a fail icon
22-
<FontAwesomeIcon icon={faExclamationCircle} className='fail' size='lg' />
20+
<FontAwesomeIcon icon={faExclamationCircle} className='fail' size='lg' /> // if the result boolean is false, we display a fail icon
2321
);
2422

25-
// Returns the Loader component
2623
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
24+
// Returns the 'Loader' component
2725
const Loader = ({ loading, result }): JSX.Element =>
2826
loading ? (
29-
// if the loadingArray value is true, we display a loading icon
30-
<ClipLoader color='#123abc' size={30} loading={loading} />
27+
<ClipLoader color='#123abc' size={30} loading={loading} /> // if the loadingArray value is true, we display a loading icon
3128
) : (
32-
// else we display a component produced by handleResult depending on if the result parameter (which takes an argument from the status object in ErrorContainer) is true or false
33-
handleResult(result)
29+
handleResult(result) // else we display a component produced by 'handleResult' depending on if the result parameter (which takes an argument from the status object in 'ErrorContainer') is true or false
3430
);
3531

3632
export default Loader;

src/app/components/MainSlider.tsx

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,50 +5,53 @@ import { changeSlider, pause } from '../actions/actions';
55
import { useStoreContext } from '../store';
66
import { HandleProps, MainSliderProps } from '../FrontendTypes';
77

8-
const { Handle } = Slider;
8+
const { Handle } = Slider; // component constructor of Slider that allows customization of the handle
99

1010
const handle = (props: HandleProps): JSX.Element => {
1111
const { value, dragging, index, ...restProps } = props;
1212

1313
return (
14-
<Tooltip
14+
<Tooltip // Tooltip that pop's up when clicking/dragging the slider thumb/handle that displays the current snapshot index
1515
prefixCls='rc-slider-tooltip'
16-
overlay={value}
17-
visible={dragging}
18-
placement='top'
16+
overlay={value} // the currentIndex
17+
visible={dragging} // tooltip only visible when slider thumb is click and/or dragged
18+
placement='top' // display the tooltip above the slider thumb
1919
key={index}
2020
>
21-
<Handle value={value} {...restProps} />
21+
<Handle
22+
value={value} // the currentIndex / slider thumb position on the slider
23+
{...restProps}
24+
/>
2225
</Tooltip>
2326
);
2427
};
2528

2629

2730
function MainSlider(props: MainSliderProps): JSX.Element {
28-
const { snapshotsLength } = props;
29-
const [{ tabs, currentTab }, dispatch] = useStoreContext();
30-
const { currLocation } = tabs[currentTab];
31-
const [sliderIndex, setSliderIndex] = useState(0);
31+
const { snapshotsLength } = props; // destructure props to get our total number of snapshots
32+
const [{ tabs, currentTab }, dispatch] = useStoreContext(); // 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
33+
const { currLocation } = tabs[currentTab]; // we destructure the currentTab object
34+
const [sliderIndex, setSliderIndex] = useState(0); // create a local state 'sliderIndex' and set it to 0.
3235

3336
useEffect(() => {
34-
if (currLocation) {
35-
setSliderIndex(currLocation.index);
37+
if (currLocation) { // if we have a 'currLocation'
38+
setSliderIndex(currLocation.index); // set our slider thumb position to the 'currLocation.index'
3639
} else {
37-
setSliderIndex(0);
40+
setSliderIndex(0); // just set the thumb position to the beginning
3841
}
39-
}, [currLocation]);
42+
}, [currLocation]); // if currLocation changes, rerun useEffect
4043

4144
return (
4245
<Slider
43-
min={0}
44-
max={snapshotsLength - 1}
45-
value={sliderIndex}
46-
onChange={(index: any) => {
47-
setSliderIndex(index);
46+
min={0} // index of our first snapshot
47+
max={snapshotsLength - 1} // index of our last snapshot
48+
value={sliderIndex} // currently slider thumb position
49+
onChange={(index: any) => { // when the slider position changes
50+
setSliderIndex(index); // update the sliderIndex
4851
}}
49-
onAfterChange={() => {
50-
dispatch(changeSlider(sliderIndex));
51-
dispatch(pause());
52+
onAfterChange={() => { // after updating the sliderIndex
53+
dispatch(changeSlider(sliderIndex)); // updates currentTab's 'sliderIndex' and replaces our snapshot with the appropriate snapshot[sliderIndex]
54+
dispatch(pause()); // pauses playing and sets currentTab object'a intervalId to null
5255
}}
5356
handle={handle}
5457
/>

src/app/containers/ActionContainer.tsx

Lines changed: 32 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,15 @@ const resetSlider = () => {
2626

2727

2828
function ActionContainer(props): JSX.Element {
29-
// 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
30-
const [{ tabs, currentTab, port }, dispatch] = useStoreContext();
31-
32-
// we destructure the currentTab object
33-
const { currLocation, hierarchy, sliderIndex, viewIndex } = tabs[currentTab];
34-
35-
// we destructure our props object
36-
const { toggleActionContainer, actionView, setActionView } = props;
37-
38-
// We create a local state 'recordingActions' and set it to true
39-
const [recordingActions, setRecordingActions] = useState(true);
40-
41-
// we create an array 'actionsArr' that will hold elements we create later on
42-
let actionsArr: JSX.Element[] = [];
29+
const [{ tabs, currentTab, port }, dispatch] = useStoreContext(); // 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
30+
const { currLocation, hierarchy, sliderIndex, viewIndex } = tabs[currentTab]; // we destructure the currentTab object
31+
const { toggleActionContainer, actionView, setActionView } = props; // we destructure our props object
32+
const [recordingActions, setRecordingActions] = useState(true); // We create a local state 'recordingActions' and set it to true
33+
let actionsArr: JSX.Element[] = []; // we create an array 'actionsArr' that will hold elements we create later on
4334
// we create an array 'hierarchyArr' that will hold objects and numbers
4435
const hierarchyArr: (number | {})[] = [];
4536

4637
/*
47-
4838
function to traverse state from hierarchy and also getting information on display name and component name
4939
5040
the obj parameter is an object with the following structure:
@@ -58,22 +48,16 @@ function ActionContainer(props): JSX.Element {
5848
index: number;
5949
children?: [];
6050
}
61-
6251
*/
6352

6453
const displayArray = (obj: Obj): void => {
6554
if (
66-
// if the 'stateSnapshot' has a non-empty 'children' array
67-
obj.stateSnapshot.children.length > 0 &&
68-
// and there is an element
69-
obj.stateSnapshot.children[0] &&
70-
// with a 'state'
71-
obj.stateSnapshot.children[0].state &&
72-
// and a 'name'
73-
obj.stateSnapshot.children[0].name
55+
obj.stateSnapshot.children.length > 0 && // if the 'stateSnapshot' has a non-empty 'children' array
56+
obj.stateSnapshot.children[0] && // and there is an element
57+
obj.stateSnapshot.children[0].state && // with a 'state'
58+
obj.stateSnapshot.children[0].name // and a 'name'
7459
) {
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'.
76-
const newObj: Record<string, unknown> = {
60+
const newObj: Record<string, unknown> = { // 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'.
7761
index: obj.index,
7862
displayName: `${obj.name}.${obj.branch}`,
7963
state: obj.stateSnapshot.children[0].state,
@@ -84,39 +68,36 @@ function ActionContainer(props): JSX.Element {
8468
? ''
8569
: obj.stateSnapshot.children[0].componentData,
8670
};
87-
// we push our record object into 'hiearchyArr' defined on line 41
88-
hierarchyArr.push(newObj);
71+
hierarchyArr.push(newObj); // we push our record object into 'hiearchyArr' defined on line 35
8972
}
90-
// if argument has a 'children' array, we iterate through it and run 'displayArray' on each element
91-
if (obj.children) {
73+
74+
if (obj.children) { // if argument has a 'children' array, we iterate through it and run 'displayArray' on each element
9275
obj.children.forEach((element): void => {
9376
displayArray(element);
9477
});
9578
}
9679
};
9780

9881
// the hierarchy gets set on the first click in the page
99-
// when page in refreshed we may not have a hierarchy so we need to check if hierarchy was initialized
100-
// if true invoke displayArray to display the hierarchy
101-
if (hierarchy) displayArray(hierarchy);
82+
if (hierarchy) displayArray(hierarchy); // when page is refreshed we may not have a hierarchy so we need to check if hierarchy was initialized. If it was initialized, invoke displayArray to display the hierarchy
10283

10384
// 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
10485
function handleOnKeyDown(e: KeyboardEvent, i: number): void {
10586
let currIndex = i;
106-
// up arrow key pressed
107-
if (e.key === 'ArrowUp') {
87+
88+
if (e.key === 'ArrowUp') { // up arrow key pressed
10889
currIndex -= 1;
10990
if (currIndex < 0) return;
11091
dispatch(changeView(currIndex));
11192
}
112-
// down arrow key pressed
113-
else if (e.key === 'ArrowDown') {
93+
94+
else if (e.key === 'ArrowDown') { // down arrow key pressed
11495
currIndex += 1;
11596
if (currIndex > hierarchyArr.length - 1) return;
11697
dispatch(changeView(currIndex));
11798
}
118-
// enter key pressed
119-
else if (e.key === 'Enter') {
99+
100+
else if (e.key === 'Enter') { // enter key pressed
120101
e.stopPropagation(); // prevents further propagation of the current event in the capturing and bubbling phases
121102
e.preventDefault(); // needed or will trigger onClick right after
122103
dispatch(changeSlider(currIndex));
@@ -136,12 +117,10 @@ function ActionContainer(props): JSX.Element {
136117
componentName: string;
137118
componentData: { actualDuration: number } | undefined;
138119
}) => {
139-
// destructure index from snapshot
140-
const { index } = snapshot;
141-
// boolean on whether the current index is the same as the viewIndex
142-
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
144-
const last = viewIndex === -1 && index === hierarchyArr.length - 1;
120+
const { index } = snapshot; // destructure index from snapshot
121+
const selected = index === viewIndex; // boolean on whether the current index is the same as the viewIndex
122+
const last = viewIndex === -1 && index === hierarchyArr.length - 1; // 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
123+
145124
/*
146125
====================================================
147126
// boolean
@@ -172,6 +151,7 @@ function ActionContainer(props): JSX.Element {
172151
useEffect(() => {
173152
setActionView(true);
174153
// !!!! Why is the dependency array the function being called within the useEffect? !!!!
154+
// may not call an infinite loop since it involves a setter function
175155
}, [setActionView]);
176156

177157
// Function sends message to background.js which sends message to the content script
@@ -180,23 +160,20 @@ function ActionContainer(props): JSX.Element {
180160
action: 'toggleRecord',
181161
tabId: currentTab,
182162
});
183-
// Record button's icon is being togggled on click
184-
setRecordingActions(!recordingActions);
163+
setRecordingActions(!recordingActions); // Record button's icon is being togggled on click
185164
};
186165

187-
// Logic to create the route description components
188166
type routes = {
189167
[route: string]: [];
190168
};
191169

192-
const routes: {} = {};
193-
// iterate through our actionsArr
194-
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]
170+
const routes: {} = {}; // Logic to create the route description components begin
171+
172+
for (let i = 0; i < actionsArr.length; i += 1) { // iterate through our actionsArr
196173
if (!routes.hasOwnProperty(actionsArr[i].props.routePath)) {
197-
routes[actionsArr[i].props.routePath] = [actionsArr[i]];
198-
} else {
199-
routes[actionsArr[i].props.routePath].push(actionsArr[i]);
174+
routes[actionsArr[i].props.routePath] = [actionsArr[i]]; // 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].
175+
} else {
176+
routes[actionsArr[i].props.routePath].push(actionsArr[i]); // If it does exist, we push the component at index [i] to the apporpriate routes[routePath]
200177
}
201178
}
202179

0 commit comments

Comments
 (0)