Skip to content

Commit b33d7c1

Browse files
authored
Merge pull request #3725 from chrisgarrity/issue/www-2281-tutorials
Handle ?tutorial= query in gui
2 parents 2f4f8a1 + 3efab34 commit b33d7c1

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

src/containers/gui.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
getIsShowingProject
1414
} from '../reducers/project-state';
1515
import {setProjectTitle} from '../reducers/project-title';
16+
import {detectTutorialId} from '../lib/tutorial-from-url';
17+
import {activateDeck} from '../reducers/cards';
1618
import {
1719
activateTab,
1820
BLOCKS_TAB_INDEX,
@@ -47,6 +49,7 @@ class GUI extends React.Component {
4749
componentDidMount () {
4850
this.setReduxTitle(this.props.projectTitle);
4951
this.props.onStorageInit(storage);
52+
this.setActiveCards(detectTutorialId());
5053
}
5154
componentDidUpdate (prevProps) {
5255
if (this.props.projectId !== prevProps.projectId && this.props.projectId !== null) {
@@ -65,6 +68,11 @@ class GUI extends React.Component {
6568
this.props.onUpdateReduxProjectTitle(newTitle);
6669
}
6770
}
71+
setActiveCards (tutorialId) {
72+
if (tutorialId && tutorialId !== 'all') {
73+
this.props.onUpdateReduxDeck(tutorialId);
74+
}
75+
}
6876
render () {
6977
if (this.props.isError) {
7078
throw new Error(
@@ -80,6 +88,7 @@ class GUI extends React.Component {
8088
isShowingProject,
8189
onStorageInit,
8290
onUpdateProjectId,
91+
onUpdateReduxDeck,
8392
onUpdateReduxProjectTitle,
8493
projectHost,
8594
projectId,
@@ -119,6 +128,7 @@ GUI.propTypes = {
119128
onStorageInit: PropTypes.func,
120129
onUpdateProjectId: PropTypes.func,
121130
onUpdateProjectTitle: PropTypes.func,
131+
onUpdateReduxDeck: PropTypes.func,
122132
onUpdateReduxProjectTitle: PropTypes.func,
123133
previewInfoVisible: PropTypes.bool,
124134
projectHost: PropTypes.string,
@@ -169,6 +179,7 @@ const mapDispatchToProps = dispatch => ({
169179
onActivateSoundsTab: () => dispatch(activateTab(SOUNDS_TAB_INDEX)),
170180
onRequestCloseBackdropLibrary: () => dispatch(closeBackdropLibrary()),
171181
onRequestCloseCostumeLibrary: () => dispatch(closeCostumeLibrary()),
182+
onUpdateReduxDeck: tutorialId => dispatch(activateDeck(tutorialId)),
172183
onUpdateReduxProjectTitle: title => dispatch(setProjectTitle(title))
173184
});
174185

src/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import GUI from './containers/gui.jsx';
22
import AppStateHOC from './lib/app-state-hoc.jsx';
3-
import {detectTutorialId} from './lib/tutorial-from-url';
4-
import GuiReducer, {guiInitialState, guiMiddleware, initFullScreen, initPlayer, initTutorialCard} from './reducers/gui';
3+
import GuiReducer, {guiInitialState, guiMiddleware, initFullScreen, initPlayer} from './reducers/gui';
54
import LocalesReducer, {localesInitialState, initLocale} from './reducers/locales';
65
import {ScratchPaintReducer} from 'scratch-paint';
76
import {setFullScreen, setPlayer} from './reducers/mode';
@@ -25,7 +24,5 @@ export {
2524
initLocale,
2625
localesInitialState,
2726
setFullScreen,
28-
setPlayer,
29-
detectTutorialId,
30-
initTutorialCard
27+
setPlayer
3128
};

src/lib/app-state-hoc.jsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ const AppStateHOC = function (WrappedComponent, localesOnly) {
3131
let reducers = {};
3232
let enhancer;
3333

34+
this.state = {
35+
tutorial: false
36+
};
37+
3438
let initializedLocales = localesInitialState;
3539
const locale = detectLocale(Object.keys(locales));
3640
if (locale !== 'en') {
@@ -52,7 +56,6 @@ const AppStateHOC = function (WrappedComponent, localesOnly) {
5256
guiMiddleware,
5357
initFullScreen,
5458
initPlayer,
55-
initTutorialCard,
5659
initTutorialLibrary
5760
} = guiRedux;
5861
const {ScratchPaintReducer} = require('scratch-paint');
@@ -67,16 +70,11 @@ const AppStateHOC = function (WrappedComponent, localesOnly) {
6770
}
6871
} else {
6972
const tutorialId = detectTutorialId();
70-
if (tutorialId !== null) {
71-
// When loading a tutorial from the URL,
72-
// load w/o preview modal
73-
// open requested tutorial card or tutorials library modal for 'all'
74-
if (tutorialId === 'all') {
75-
initializedGui = initTutorialLibrary(initializedGui);
76-
} else {
77-
initializedGui = initTutorialCard(initializedGui, tutorialId);
78-
}
79-
}
73+
// handle ?tutorial=all for beta
74+
// if we decide to keep this for www, functionality should move to
75+
// setActiveCards in the GUI container
76+
if (tutorialId === 'all') initializedGui = initTutorialLibrary(initializedGui);
77+
if (tutorialId) this.state.tutorial = true;
8078
}
8179
reducers = {
8280
locales: localesReducer,
@@ -111,10 +109,13 @@ const AppStateHOC = function (WrappedComponent, localesOnly) {
111109
isPlayerOnly, // eslint-disable-line no-unused-vars
112110
...componentProps
113111
} = this.props;
112+
if (this.state.tutorial) componentProps.hideIntro = true;
114113
return (
115114
<Provider store={this.store}>
116115
<ConnectedIntlProvider>
117-
<WrappedComponent {...componentProps} />
116+
<WrappedComponent
117+
{...componentProps}
118+
/>
118119
</ConnectedIntlProvider>
119120
</Provider>
120121
);

0 commit comments

Comments
 (0)