Skip to content

Commit 649896c

Browse files
authored
Merge branch 'dev' into TravelContainerComponents
2 parents ce4f918 + e76fcd6 commit 649896c

File tree

8 files changed

+75
-45
lines changed

8 files changed

+75
-45
lines changed

src/app/FrontendTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export interface ActionProps {
159159
last: boolean;
160160
index: number;
161161
sliderIndex: number;
162-
dispatch: (a: { type: string; payload: unknown }) => void;
162+
// dispatch: (a: { type: string; payload: unknown }) => void;
163163
displayName: string;
164164
componentName: string;
165165
componentData: { actualDuration: number } | undefined;

src/app/RTKslices.tsx

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ export const mainSlice = createSlice({
364364
tabs[currentTab].sliderIndex = 0;
365365
console.log('resetSlider: state end', current(state));
366366

367+
367368
},
368369

369370

@@ -388,40 +389,47 @@ export const mainSlice = createSlice({
388389
});
389390
console.log('Toggle Mode: state end', current(state));
390391

392+
391393
},
392394
importSnapshots: (state, action) => {
393395
console.log('importSnapshots: ', current(state));
394396

395397
const { port, tabs, currentTab } = state;
396-
// Log the value of tabs[currentTab].snapshots before the update
397-
port.postMessage({
398-
action: 'import',
399-
payload: action.payload,
400-
tabId: currentTab,
401-
});
402-
403-
const savedSnapshot = action.payload;
404-
405-
tabs[currentTab].sliderIndex = savedSnapshot.sliderIndex;
406-
tabs[currentTab].viewIndex = savedSnapshot.viewIndex;
407-
tabs[currentTab].playing = false;
408-
409-
// resets hierarchy to page last state recorded
410-
tabs[currentTab].hierarchy.stateSnapshot = savedSnapshot.hierarchy.stateSnapshot;
411-
412-
// resets hierarchy
413-
tabs[currentTab].hierarchy.children = savedSnapshot.hierarchy.children;
414-
415-
// resets snapshots to page last state recorded
416-
tabs[currentTab].snapshots = savedSnapshot.snapshots;
417-
418-
// resets currLocation to page last state recorded
419-
tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
420-
tabs[currentTab].index = savedSnapshot.index;
421-
tabs[currentTab].currParent = savedSnapshot.currParent;
422-
tabs[currentTab].currBranch = savedSnapshot.Branch;
423-
tabs[currentTab].seriesSavedStatus = false;
424-
console.log('importSnapshots: state end', current(state));
398+
399+
// Log the value of tabs[currentTab].snapshots before the update
400+
port.postMessage({
401+
action: 'import',
402+
payload: action.payload,
403+
tabId: currentTab,
404+
});
405+
406+
const savedSnapshot = action.payload;
407+
408+
tabs[currentTab].sliderIndex = savedSnapshot.sliderIndex;
409+
tabs[currentTab].viewIndex = savedSnapshot.viewIndex;
410+
tabs[currentTab].playing = false;
411+
412+
// resets hierarchy to page last state recorded
413+
tabs[currentTab].hierarchy.stateSnapshot = savedSnapshot.hierarchy.stateSnapshot;
414+
415+
// resets hierarchy
416+
tabs[currentTab].hierarchy.children = savedSnapshot.hierarchy.children;
417+
418+
// resets snapshots to page last state recorded
419+
tabs[currentTab].snapshots = savedSnapshot.snapshots;
420+
421+
// resets currLocation to page last state recorded
422+
tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
423+
tabs[currentTab].index = savedSnapshot.index;
424+
tabs[currentTab].currParent = savedSnapshot.currParent;
425+
tabs[currentTab].currBranch = savedSnapshot.Branch;
426+
tabs[currentTab].seriesSavedStatus = false;
427+
console.log('importSnapshots: state end', current(state));
428+
429+
},
430+
tutorialSaveSeriesToggle: (state, action) => {
431+
const { tabs, currentTab } = state;
432+
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: action.payload }
425433

426434
}
427435
},
@@ -447,7 +455,8 @@ export const {
447455
moveBackward,
448456
resetSlider,
449457
toggleMode,
450-
importSnapshots
458+
importSnapshots,
459+
tutorialSaveSeriesToggle
451460
} = mainSlice.actions
452461

453462

src/app/components/Action.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
import React from 'react';
66
import ReactHover, { Trigger, Hover } from 'react-hover';
7-
import { changeView, changeSlider } from '../actions/actions';
7+
import { changeView, changeSlider } from '../RTKslices';
88
import { ActionProps, OptionsCursorTrueWithMargin } from '../FrontendTypes';
9+
import { useDispatch } from 'react-redux';
910

1011
/*
1112
This render's the individual snapshot components on the left side column
@@ -27,13 +28,18 @@ import { ActionProps, OptionsCursorTrueWithMargin } from '../FrontendTypes';
2728
*/
2829

2930
const Action = (props: ActionProps): JSX.Element => {
31+
32+
//here we are adding useSelector and useDispatch for RTK state conversion
33+
const dispatch = useDispatch();
34+
3035
// We destructure the 'props' that were passed into this component
3136
const {
3237
selected, // boolean on whether the current index is the same as the viewIndex in 'ActionContainer'
3338
last, // 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) in 'ActionContainer'
3439
index, // from snapshot.index in "ActionContainer's" 'hierarchyArr'
3540
sliderIndex, // from tabs[currentTab] object in 'ActionContainer'
36-
dispatch,
41+
//commented out dispatch that was prop drilled as conversion to RTX might invalidate need for prop drilling to access dispatch
42+
// dispatch,
3743
displayName, // from snapshot.displayName in "ActionContainer's" 'hierarchyArr'
3844
componentData, // from snapshot.componentData in "ActionContainer's" 'hierarchyArr'
3945
viewIndex, // from tabs[currentTab] object in 'ActionContainer'

src/app/components/StateRoute/History.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function History(props: Record<string, unknown>): JSX.Element {
3333
height: totalHeight, // from ParentSize provided in StateRoute
3434
margin = defaultMargin,
3535
hierarchy, // from 'tabs[currentTab]' object in 'MainContainer'
36-
dispatch, // from useStoreContext in 'StateRoute'
36+
// dispatch, // from useStoreContext in 'StateRoute'
3737
currLocation, // from 'tabs[currentTab]' object in 'MainContainer'
3838
snapshots, // from 'tabs[currentTab].snapshotDisplay' object in 'MainContainer'
3939
} = props;

src/app/components/StateRoute/StateRoute.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { ParentSize } from '@visx/responsive';
1111
import Tree from './Tree';
1212
import ComponentMap from './ComponentMap/ComponentMap';
1313
import { changeView, changeSlider } from '../../actions/actions';
14-
import { useStoreContext } from '../../store';
14+
// import { useStoreContext } from '../../store';
15+
import { useDispatch, useSelector } from 'react-redux';
1516
import PerformanceVisx from './PerformanceVisx/PerformanceVisx';
1617
import WebMetrics from '../WebMetrics';
1718
import { StateRouteProps } from '../../FrontendTypes'
@@ -32,7 +33,11 @@ const StateRoute = (props: StateRouteProps) => {
3233
webMetrics, // from 'tabs[currentTab]' object in 'MainContainer'
3334
currLocation // from 'tabs[currentTab]' object in 'MainContainer'
3435
} = props;
35-
const [{ tabs, currentTab }, dispatch] = useStoreContext();
36+
// const [{ tabs, currentTab }, dispatch] = useStoreContext();
37+
38+
// Don't believe we need dispatch here because all it was used for was to prop drill, and I removed that functionality
39+
// const dispatch = useDispatch();
40+
const { tabs, currentTab } = useSelector((state: any) => state.main);
3641
const { hierarchy, sliderIndex, viewIndex } = tabs[currentTab];
3742

3843
const renderComponentMap = () => {
@@ -62,7 +67,8 @@ const StateRoute = (props: StateRouteProps) => {
6267
width={width}
6368
height={height}
6469
hierarchy={hierarchy}
65-
dispatch={dispatch}
70+
// Commented out dispatch that was prop drilled as conversion to RTK might invalidate need for prop drilling to access dispatch
71+
// dispatch={dispatch}
6672
sliderIndex={sliderIndex}
6773
viewIndex={viewIndex}
6874
currLocation={currLocation}

src/app/components/Tutorial.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import * as React from 'react';
66
import { Component } from 'react';
77
import 'intro.js/introjs.css';
8-
import { tutorialSaveSeriesToggle, setCurrentTabInApp } from '../actions/actions';
8+
// 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';
1212
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/
13-
13+
import { setCurrentTabInApp, tutorialSaveSeriesToggle } from '../RTKslices'
14+
import { useDispatch, useSelector } from 'react-redux';
1415
/*
1516
This is the tutorial displayed when the "How to use" button is clicked
1617
This needs to be a class component to be compatible with updateStepElement from intro.js
@@ -35,10 +36,13 @@ export default class Tutorial extends Component<TutorialProps, TutorialState> {
3536
public refs: any;
3637

3738
render(): JSX.Element {
38-
const {
39-
currentTabInApp, // 'currentTabInApp' from 'ButtonsContainer' after useStoreContext()
40-
dispatch // 'dispatch' from 'ButtonsContainer' after useStoreContext()
41-
} = this.props;
39+
// const {
40+
// currentTabInApp, // 'currentTabInApp' from 'ButtonsContainer' after useStoreContext()
41+
// dispatch // 'dispatch' from 'ButtonsContainer' after useStoreContext()
42+
// } = this.props;
43+
44+
const dispatch = useDispatch();
45+
const currentTabInApp = useSelector((state: any) => state.main.currentTabInApp);
4246

4347
// This updates the steps so that they can target dynamically rendered elements
4448
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.

src/app/containers/ActionContainer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ function ActionContainer(props): JSX.Element {
137137
componentData={snapshot.componentData}
138138
selected={selected}
139139
last={last}
140-
dispatch={dispatch}
140+
//not sure if we need to prop drill dispatch anymore as we can import it directly within action component
141+
//line 142 commented out for this reason above
142+
// dispatch={dispatch}
141143
sliderIndex={sliderIndex}
142144
handleOnkeyDown={handleOnKeyDown}
143145
viewIndex={viewIndex}

src/app/containers/ButtonsContainer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ function ButtonsContainer(): JSX.Element {
7878
Upload
7979
</Button>
8080
{/* The component below renders a button for the tutorial walkthrough of Reactime */}
81-
<Tutorial dispatch={dispatch} currentTabInApp={currentTabInApp} />
81+
<Tutorial
82+
//commented out so we can use useDispatch in Tutorial.tsx
83+
// dispatch={dispatch}
84+
currentTabInApp={currentTabInApp} />
8285
</div>
8386
);
8487
}

0 commit comments

Comments
 (0)