Skip to content

Commit 71c4d40

Browse files
authored
Merge pull request #7 from oslabs-beta/andrewb
converted tutorial.tsx and added reducer to RTK slices
2 parents 867017e + 3aea2f9 commit 71c4d40

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/app/RTKslices.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ export const mainSlice = createSlice({
339339
importSnapshots: (state, action) => {
340340
console.log('importSnapshots')
341341
const { port, tabs, currentTab } = state;
342+
342343
// Log the value of tabs[currentTab].snapshots before the update
343344
port.postMessage({
344345
action: 'import',
@@ -368,6 +369,11 @@ export const mainSlice = createSlice({
368369
tabs[currentTab].currBranch = savedSnapshot.Branch;
369370
tabs[currentTab].seriesSavedStatus = false;
370371
},
372+
tutorialSaveSeriesToggle: (state, action) => {
373+
const { tabs, currentTab } = state;
374+
tabs[currentTab] = { ...tabs[currentTab], seriesSavedStatus: action.payload }
375+
376+
}
371377
},
372378
})
373379

@@ -391,7 +397,8 @@ export const {
391397
moveBackward,
392398
resetSlider,
393399
toggleMode,
394-
importSnapshots
400+
importSnapshots,
401+
tutorialSaveSeriesToggle
395402
} = mainSlice.actions
396403

397404

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/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)