Skip to content

Commit 178d90c

Browse files
committed
added onHover onHoverExit save actions
1 parent 59860c5 commit 178d90c

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

src/app/RTKslices.tsx

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,46 @@ export const mainSlice = createSlice({
431431
const { tabs, currentTab } = state;
432432
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: action.payload }
433433

434+
},
435+
436+
onHover: (state, action) => {
437+
const { currentTab, port } = state;
438+
439+
port.postMessage({
440+
action: 'onHover',
441+
payload: action.payload,
442+
tabId: currentTab,
443+
});
444+
},
445+
446+
onHoverExit: (state, action) => {
447+
const { currentTab, port } = state;
448+
449+
port.postMessage({
450+
action: 'onHoverExit',
451+
payload: action.payload,
452+
tabId: currentTab,
453+
});
454+
},
455+
456+
save: (state, action) => {
457+
const { currentTab, tabs } = state;
458+
459+
const { newSeries, newSeriesName } = action.payload;
460+
if (!tabs[currentTab].seriesSavedStatus) {
461+
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: 'inputBoxOpen' };
462+
}
463+
// Runs if series name input box is active.
464+
// Updates chrome local storage with the newly saved series. Console logging the seriesArray grabbed from local storage may be helpful.
465+
if (tabs[currentTab].seriesSavedStatus === 'inputBoxOpen') {
466+
//Set a type for seriesArray 10/04/2023
467+
let seriesArray: any = localStorage.getItem('project');
468+
seriesArray = seriesArray === null ? [] : JSON.parse(seriesArray);
469+
newSeries.name = newSeriesName;
470+
seriesArray.push(newSeries);
471+
localStorage.setItem('project', JSON.stringify(seriesArray));
472+
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: 'saved' };
473+
}
434474
}
435475
},
436476
})
@@ -456,7 +496,10 @@ export const {
456496
resetSlider,
457497
toggleMode,
458498
importSnapshots,
459-
tutorialSaveSeriesToggle
499+
tutorialSaveSeriesToggle,
500+
onHover,
501+
onHoverExit,
502+
460503
} = mainSlice.actions
461504

462505

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import { scaleBand, scaleLinear, scaleOrdinal } from '@visx/scale';
88
import { useTooltip, useTooltipInPortal, defaultStyles } from '@visx/tooltip';
99
import { Text } from '@visx/text';
1010
import { schemeSet1 } from 'd3-scale-chromatic';
11-
import { onHover, onHoverExit, save } from '../../../actions/actions';
12-
import { useStoreContext } from '../../../store';
11+
import { onHover, onHoverExit, save } from '../../../RTKslices';
12+
// import { useStoreContext } from '../../../store';
13+
import { useDispatch, useSelector } from 'react-redux';
1314
import { snapshot, TooltipData, Margin, BarGraphProps } from '../../../FrontendTypes';
1415

1516
/* DEFAULTS */
@@ -32,7 +33,10 @@ const tooltipStyles = {
3233
};
3334

3435
const BarGraph = (props: BarGraphProps): JSX.Element => {
35-
const [{ tabs, currentTab }, dispatch] = useStoreContext();
36+
const dispatch = useDispatch();
37+
// const [{ tabs, currentTab }, dispatch] = useStoreContext();
38+
const { tabs, currentTab } = useSelector((state: any) => state.main);
39+
3640
const {
3741
width, // from stateRoute container
3842
height, // from stateRoute container

0 commit comments

Comments
 (0)