Skip to content

Commit 05f45ba

Browse files
added more pseudocode
1 parent b6cf3e6 commit 05f45ba

File tree

2 files changed

+38
-34
lines changed

2 files changed

+38
-34
lines changed

src/app/components/Tutorial.tsx

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { tutorialSaveSeriesToggle, setCurrentTabInApp } from '../actions/actions
99
import { TutorialProps, TutorialState, StepsObj } from '../FrontendTypes';
1010
import { Button } from '@mui/material';
1111
import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
12-
const { Steps } = require('intro.js-react'); //Must be required in. This enables compatibility with TS. If imported in, throws ts error of not rendering steps as a class component correctly.
12+
const { Steps } = require('intro.js-react'); //Must be required in. This enables compatibility with TS. If imported in, throws ts error of not rendering steps as a class component correctly. The package 'intro.js-react' is small React wrapper around Intro.js. The wrapper provides support for both steps and hints. https://introjs.com/docs/
1313

1414
/*
1515
This is the tutorial displayed when the "How to use" button is clicked
@@ -35,49 +35,53 @@ export default class Tutorial extends Component<TutorialProps, TutorialState> {
3535
public refs: any;
3636

3737
render(): JSX.Element {
38-
const { currentTabInApp, dispatch } = this.props;
38+
const {
39+
currentTabInApp, // 'currentTabInApp' from 'ButtonsContainer' after useStoreContext()
40+
dispatch // 'dispatch' from 'ButtonsContainer' after useStoreContext()
41+
} = this.props;
3942

4043
// This updates the steps so that they can target dynamically rendered elements
41-
const onChangeHandler = (currentStepIndex: number) => {
44+
const onChangeHandler = (currentStepIndex: number) => { // takes in the current step and updates the tab[currentTab]'s seriesSavedStatus based on conditions and updates the element associated with the step.
4245
if (currentTabInApp === 'performance' && currentStepIndex === 1) {
43-
dispatch(tutorialSaveSeriesToggle('inputBoxOpen'));
44-
this.steps.updateStepElement(currentStepIndex);
46+
dispatch(tutorialSaveSeriesToggle('inputBoxOpen')); // sends a dispatch that update's tab[currentTab]'s 'seriesSavedStatus' to 'inputBoxOpen'
47+
this.steps.updateStepElement(currentStepIndex); // Built in intro.js API that updates element associated with step
4548
}
49+
4650
if (currentTabInApp === 'performance' && currentStepIndex === 2) {
4751
this.steps.updateStepElement(currentStepIndex);
4852
}
53+
4954
if (currentTabInApp === 'performance' && currentStepIndex === 4) {
50-
dispatch(tutorialSaveSeriesToggle('saved'));
55+
dispatch(tutorialSaveSeriesToggle('saved')); // sends a dispatch that update's tab[currentTab]'s 'seriesSavedStatus' to 'saved'
5156
this.steps.updateStepElement(currentStepIndex);
5257
}
58+
5359
if (currentTabInApp === 'performance' && currentStepIndex === 5) {
5460
this.steps.updateStepElement(currentStepIndex);
5561
dispatch(setCurrentTabInApp('performance-comparison')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'performance-comparison.' to facilitate render.
5662
}
63+
5764
if (currentTabInApp === 'performance-comparison' && currentStepIndex === 6) {
58-
dispatch(tutorialSaveSeriesToggle(false));
65+
dispatch(tutorialSaveSeriesToggle(false)); // sends a dispatch that update's tab[currentTab]'s 'seriesSavedStatus' to the boolean 'false'
5966
}
6067
};
6168

62-
const onExit = () => {
63-
this.setState({ stepsEnabled: false });
69+
const onExit = () => { // This callback is called when the tutorial exits
70+
this.setState({ stepsEnabled: false }); // sets stepsEnabled to false in this component's state
6471
};
65-
const startIntro = () => {
66-
// If "How to use" is clicked while in the performance tab,
67-
// we'll navigate to the snapshops view before starting the tutorial
68-
// This is because the tutorial steps are designed to begin on the snapshots sub-tab
69-
// Check out the PerformanceVisx component to see the route redirect logic
72+
73+
const startIntro = () => { // If "How to use" is clicked while in the performance tab, we'll navigate to the snapshops view before starting the tutorial. This is because the tutorial steps are designed to begin on the snapshots sub-tab. Check out the 'PerformanceVisx' component to see the route redirect logic
7074
if (
7175
currentTabInApp === 'performance' ||
7276
currentTabInApp === 'performance-comparison' ||
7377
currentTabInApp === 'performance-component-details'
7478
) {
7579
dispatch(setCurrentTabInApp('performance')); // dispatch sent at initial page load allowing changing "immer's" draft.currentTabInApp to 'performance' to facilitate render.
7680
}
77-
this.setState({ stepsEnabled: true });
81+
this.setState({ stepsEnabled: true }); // sets stepsEnabled to false in this component's state
7882
};
7983

80-
let steps: StepsObj[] = [];
84+
let steps: StepsObj[] = []; // the steps array will be populated with tutorial elements based on the 'currentTabInApp' case. This allows for specific tutorials based on the current page the user is viewing.
8185

8286
switch (currentTabInApp) {
8387
case 'map':
@@ -331,26 +335,26 @@ export default class Tutorial extends Component<TutorialProps, TutorialState> {
331335
return (
332336
<>
333337
<Steps
334-
enabled={this.state.stepsEnabled}
335-
steps={steps}
336-
initialStep={0}
337-
onExit={onExit}
338+
enabled={this.state.stepsEnabled} // Defines if steps are visible or not, default is false
339+
steps={steps} // Array of steps
340+
initialStep={0} // Step index to start with when showing the steps
341+
onExit={onExit} // Callback called when the steps are disabled. Keeps track of state when steps are dismissed with an Intro.js event and not the enabled prop
338342
options={{
339343
tooltipClass: 'customTooltip',
340-
scrollToElement: false,
341-
showProgress: true,
342-
showStepNumbers: true,
343-
showBullets: false,
344-
exitOnOverlayClick: false,
345-
doneLabel: 'Done',
346-
nextLabel: 'Next',
347-
hideNext: false,
348-
skipLabel: 'Skip',
349-
keyboardNavigation: true,
350-
overlayOpacity: 0.85,
344+
scrollToElement: false, // Enables scrolling to hidden elements
345+
showProgress: true, // Shows progress indicator
346+
showStepNumbers: true, // Show steps number in a red circle
347+
showBullets: false, // Show bullets
348+
exitOnOverlayClick: false, // Exit by clicking on the overlay layer
349+
doneLabel: 'Done', // Done button label
350+
nextLabel: 'Next', // Next button label
351+
hideNext: false, // Hide the Next button in the last step
352+
skipLabel: 'Skip', // Skip button label
353+
keyboardNavigation: true, // allows navigation between steps using the keyboard
354+
overlayOpacity: 0.85, // opacity of the overlay
351355
}}
352-
onBeforeChange={(currentStepIndex) => onChangeHandler(currentStepIndex)}
353-
ref={(steps) => (this.steps = steps)}
356+
onBeforeChange={(currentStepIndex) => onChangeHandler(currentStepIndex)} // Callback called before changing the current step.
357+
ref={(steps) => (this.steps = steps)} // ref allows access to intro.js API
354358
/>
355359
<Button
356360
variant='outlined'

src/app/reducers/mainReducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ export default (state, action) =>
426426
}
427427

428428
case types.TUTORIAL_SAVE_SERIES_TOGGLE: {
429-
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: action.payload };
429+
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: action.payload }; // sets the tab[currentTab]'s 'seriesSavedStatus' property to the payload.
430430
break;
431431
}
432432

0 commit comments

Comments
 (0)