Skip to content

Commit f8b8177

Browse files
authored
Merge pull request #14 from oslabs-beta/BarGraph
Bar graph
2 parents 44526ef + 7f4dc39 commit f8b8177

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

src/app/RTKslices.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,45 @@ export const mainSlice = createSlice({
433433
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: action.payload }
434434

435435
},
436+
437+
onHover: (state, action) => {
438+
const { currentTab, port } = state;
439+
440+
port.postMessage({
441+
action: 'onHover',
442+
payload: action.payload,
443+
tabId: currentTab,
444+
});
445+
},
446+
447+
onHoverExit: (state, action) => {
448+
const { currentTab, port } = state;
449+
450+
port.postMessage({
451+
action: 'onHoverExit',
452+
payload: action.payload,
453+
tabId: currentTab,
454+
});
455+
},
456+
457+
save: (state, action) => {
458+
const { currentTab, tabs } = state;
459+
460+
const { newSeries, newSeriesName } = action.payload;
461+
if (!tabs[currentTab].seriesSavedStatus) {
462+
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: 'inputBoxOpen' };
463+
}
464+
// Runs if series name input box is active.
465+
// Updates chrome local storage with the newly saved series. Console logging the seriesArray grabbed from local storage may be helpful.
466+
if (tabs[currentTab].seriesSavedStatus === 'inputBoxOpen') {
467+
//Set a type for seriesArray 10/04/2023
468+
let seriesArray: any = localStorage.getItem('project');
469+
seriesArray = seriesArray === null ? [] : JSON.parse(seriesArray);
470+
newSeries.name = newSeriesName;
471+
seriesArray.push(newSeries);
472+
localStorage.setItem('project', JSON.stringify(seriesArray));
473+
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: 'saved' };
474+
},
436475
toggleExpanded: (state, action) => {
437476
const { tabs, currentTab } = state;
438477
// find correct node from currLocation and toggle isExpanded
@@ -490,6 +529,9 @@ export const {
490529
toggleMode,
491530
importSnapshots,
492531
tutorialSaveSeriesToggle,
532+
onHover,
533+
onHoverExit,
534+
save,
493535
toggleExpanded,
494536
deleteSeries
495537
} = mainSlice.actions

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)