Skip to content

Commit 626b30b

Browse files
authored
Merge pull request #3 from oslabs-beta/eivindBranch
Eivind branch
2 parents c6339c0 + 135c6be commit 626b30b

16 files changed

+281
-153
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/App.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { InitialStateProps } from '../FrontendTypes';
99
// currentTabInApp is the current active tab within Reactime (Map, Performance, History, etc).
1010
// This is used to determine the proper tutorial to render when How To button is pressed.
1111

12+
// we initialize what our initialState is here
1213
const initialState: InitialStateProps = {
1314
port: null,
1415
currentTab: null,
@@ -19,8 +20,8 @@ const initialState: InitialStateProps = {
1920

2021
function App(): JSX.Element {
2122
return (
22-
<Router>
23-
<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 */}
2425
<MainContainer />
2526
</StoreContext.Provider>
2627
</Router>

src/app/components/Dropdown.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ import React from 'react';
22
import Select from 'react-select';
33
import { DropdownProps } from '../FrontendTypes'
44

5+
/*
6+
Allows the user to change the speed of the time-travel based on the selected dropdown value
7+
Component is created in the TravelContainer.tsx
8+
*/
9+
510
const Dropdown = (props: DropdownProps): JSX.Element => {
611
const { speeds, setSpeed, selectedSpeed } = props;
712
return (
813
<Select
914
className='react-select-container'
1015
classNamePrefix='react-select'
11-
value={selectedSpeed}
12-
onChange={setSpeed}
13-
options={speeds}
16+
value={selectedSpeed} // the text displayed will be based on the currently selected speed
17+
onChange={setSpeed} // allows the speed to change upon selection
18+
options={speeds} // custom speed options that are visible to the user
1419
menuPlacement='top'
1520
/>
1621
);

src/app/components/ErrorMsg.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
/* eslint-disable react/prop-types */
22
import React from 'react';
33

4+
/*
5+
This file determines what text will be displayed to the user if any one of the following fail to load:
6+
7+
1. if the content script has been launched on the current tab
8+
2. if React Dev Tools has been installed
9+
3. if target tab contains a compatible React app
10+
11+
*/
12+
413
// parses loadingArray and status and returns the correct message
514
function parseError(loadingArray: [], status: Record<string, unknown>): string {
615
let stillLoading = true;
716
loadingArray.forEach((e) => {
817
if (e === false) stillLoading = false;
918
});
10-
// As long as everything is still loading dont diplay an error message
11-
if (stillLoading) return 'default';
12-
// Return first status that fails
19+
20+
if (stillLoading) return 'default'; // As long as everything is still loading dont diplay an error message
21+
22+
// If we're done loading everything, return the first status that fails
1323
if (!status.contentScriptLaunched) return 'Content Script Error';
1424
if (!status.reactDevToolsInstalled) return 'RDT Error';
1525
if (!status.targetPageisaReactApp) return 'Not React App';
1626
return 'default';
1727
}
1828

1929
function ErrorMsg({ loadingArray, status, launchContent }): JSX.Element {
20-
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
2131
case 'Content Script Error':
2232
return (
2333
<div>

src/app/components/Loader.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,28 @@ import { ClipLoader } from 'react-spinners';
55
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
66
import { faCheck, faExclamationCircle } from '@fortawesome/free-solid-svg-icons';
77

8-
// Displays the result of the check when loading is done
8+
/*
9+
This file is what decides what icon (loading, checkmark, exclamation point) is displayed next to the checks in the ErrorContainer loading screen:
10+
11+
1. if the content script has been launched on the current tab
12+
2. if React Dev Tools has been installed
13+
3. if target tab contains a compatible React app
14+
*/
15+
916
const handleResult = (result: boolean): JSX.Element =>
1017
result ? (
11-
<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
1219
) : (
13-
<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
1421
);
1522

16-
// Returns the Loader component
1723
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
24+
// Returns the 'Loader' component
1825
const Loader = ({ loading, result }): JSX.Element =>
1926
loading ? (
20-
<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
2128
) : (
22-
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
2330
);
2431

2532
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/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/StateRoute/PerformanceVisx/BarGraphComparison.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import { scaleBand, scaleLinear, scaleOrdinal } from '@visx/scale';
1010
import { useTooltip, useTooltipInPortal, defaultStyles } from '@visx/tooltip';
1111
import { Text } from '@visx/text';
1212
import { schemeTableau10 } from 'd3-scale-chromatic';
13-
import { styled } from '@mui/system';
14-
import Select from '@mui/material/Select';
15-
import MenuItem from '@mui/material/MenuItem';
16-
import FormControl from '@mui/material/FormControl';
1713

1814
import { onHover, onHoverExit, deleteSeries, setCurrentTabInApp } from '../../../actions/actions';
1915
import { useStoreContext } from '../../../store';

src/app/components/StateRoute/PerformanceVisx/BarGraphComparisonActions.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import { scaleBand, scaleLinear, scaleOrdinal } from '@visx/scale';
88
import { useTooltip, useTooltipInPortal, defaultStyles } from '@visx/tooltip';
99
import { Text } from '@visx/text';
1010
import { schemeSet3 } from 'd3-scale-chromatic';
11-
import { styled } from '@mui/system';
12-
import Select from '@mui/material/Select';
13-
import MenuItem from '@mui/material/MenuItem';
14-
import FormControl from '@mui/material/FormControl';
1511

1612
import { deleteSeries, setCurrentTabInApp } from '../../../actions/actions';
1713
import { useStoreContext } from '../../../store';

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
};

0 commit comments

Comments
 (0)