Skip to content

Commit 93aa862

Browse files
Christopher StamperChristopher Stamper
authored andcommitted
Finished migrating StateRoute to RTK, also editted what props are received in History
1 parent e47f9d4 commit 93aa862

File tree

3 files changed

+60
-54
lines changed

3 files changed

+60
-54
lines changed

src/app/RTKslices.tsx

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,15 @@ export const mainSlice = createSlice({
305305
const { snapshots, sliderIndex} = tabs[currentTab] || {};
306306

307307
// eslint-disable-next-line max-len
308-
// resets name to 0 to send to background.js the current name in the jump action
309-
port.postMessage({
310-
action: 'jumpToSnap',
311-
index: 0,
312-
name: 0,
313-
payload: snapshots[0],
314-
tabId: currentTab,
315-
});
316-
tabs[currentTab].sliderIndex = 0;
308+
// resets name to 0 to send to background.js the current name in the jump action
309+
port.postMessage({
310+
action: 'jumpToSnap',
311+
index: 0,
312+
name: 0,
313+
payload: snapshots[0],
314+
tabId: currentTab,
315+
});
316+
tabs[currentTab].sliderIndex = 0;
317317
},
318318

319319

@@ -323,51 +323,51 @@ export const mainSlice = createSlice({
323323
const { port, tabs, currentTab } = state;
324324
const {mode} = tabs[currentTab] || {};
325325
mode[action.payload] = !mode[action.payload];
326-
const newMode = mode[action.payload];
327-
let actionText;
328-
switch (action.payload) {
329-
case 'paused':
330-
actionText = 'setPause';
331-
default:
332-
}
333-
port.postMessage({
334-
action: actionText,
335-
payload: newMode,
336-
tabId: currentTab,
337-
});
326+
const newMode = mode[action.payload];
327+
let actionText;
328+
switch (action.payload) {
329+
case 'paused':
330+
actionText = 'setPause';
331+
default:
332+
}
333+
port.postMessage({
334+
action: actionText,
335+
payload: newMode,
336+
tabId: currentTab,
337+
});
338338
},
339339
importSnapshots: (state, action) => {
340340
console.log('importSnapshots')
341341
const { port, tabs, currentTab } = state;
342-
// Log the value of tabs[currentTab].snapshots before the update
343-
port.postMessage({
344-
action: 'import',
345-
payload: action.payload,
346-
tabId: currentTab,
347-
});
348-
349-
const savedSnapshot = action.payload;
350-
351-
tabs[currentTab].sliderIndex = savedSnapshot.sliderIndex;
352-
tabs[currentTab].viewIndex = savedSnapshot.viewIndex;
353-
tabs[currentTab].playing = false;
354-
355-
// resets hierarchy to page last state recorded
356-
tabs[currentTab].hierarchy.stateSnapshot = savedSnapshot.hierarchy.stateSnapshot;
357-
358-
// resets hierarchy
359-
tabs[currentTab].hierarchy.children = savedSnapshot.hierarchy.children;
360-
361-
// resets snapshots to page last state recorded
362-
tabs[currentTab].snapshots = savedSnapshot.snapshots;
363-
364-
// resets currLocation to page last state recorded
365-
tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
366-
tabs[currentTab].index = savedSnapshot.index;
367-
tabs[currentTab].currParent = savedSnapshot.currParent;
368-
tabs[currentTab].currBranch = savedSnapshot.Branch;
369-
tabs[currentTab].seriesSavedStatus = false;
370-
}
342+
// Log the value of tabs[currentTab].snapshots before the update
343+
port.postMessage({
344+
action: 'import',
345+
payload: action.payload,
346+
tabId: currentTab,
347+
});
348+
349+
const savedSnapshot = action.payload;
350+
351+
tabs[currentTab].sliderIndex = savedSnapshot.sliderIndex;
352+
tabs[currentTab].viewIndex = savedSnapshot.viewIndex;
353+
tabs[currentTab].playing = false;
354+
355+
// resets hierarchy to page last state recorded
356+
tabs[currentTab].hierarchy.stateSnapshot = savedSnapshot.hierarchy.stateSnapshot;
357+
358+
// resets hierarchy
359+
tabs[currentTab].hierarchy.children = savedSnapshot.hierarchy.children;
360+
361+
// resets snapshots to page last state recorded
362+
tabs[currentTab].snapshots = savedSnapshot.snapshots;
363+
364+
// resets currLocation to page last state recorded
365+
tabs[currentTab].currLocation = tabs[currentTab].hierarchy;
366+
tabs[currentTab].index = savedSnapshot.index;
367+
tabs[currentTab].currParent = savedSnapshot.currParent;
368+
tabs[currentTab].currBranch = savedSnapshot.Branch;
369+
tabs[currentTab].seriesSavedStatus = false;
370+
},
371371
},
372372
})
373373

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}

0 commit comments

Comments
 (0)