Handle ?tutorial= query in gui

Moved the tutorial id handling into gui so it works when gui is embedded in www as well as standalone.

This seemed better than adding the same query handling to www, in order to pass an id to gui.

Note, the `?tutorial=all` handling remains in app-state-hoc. Currently it’s only needed in standalone mode for Hour of Code. It’s easy to move into the gui container if we do want it in gui by default.
This commit is contained in:
chrisgarrity committed 2018-11-14 15:23:02 -05:00
1 parent 9469fe13bb
commit a99ee8db0a
3 files changed
+16 -16

No files matched your search

+10
View File
@@ -13,6 +13,8 @@ import {
getIsShowingProject
} from '../reducers/project-state';
import {setProjectTitle} from '../reducers/project-title';
import {detectTutorialId} from '../lib/tutorial-from-url';
import {activateDeck} from '../reducers/cards';
import {
activateTab,
BLOCKS_TAB_INDEX,
@@ -47,6 +49,7 @@ class GUI extends React.Component {
componentDidMount () {
this.setReduxTitle(this.props.projectTitle);
this.props.onStorageInit(storage);
this.setActiveCards(detectTutorialId());
}
componentDidUpdate (prevProps) {
if (this.props.projectId !== prevProps.projectId && this.props.projectId !== null) {
@@ -65,6 +68,11 @@ class GUI extends React.Component {
this.props.onUpdateReduxProjectTitle(newTitle);
}
}
setActiveCards (tutorialId) {
if (tutorialId && tutorialId !== 'all') {
this.props.onUpdateReduxDeck(tutorialId);
}
}
render () {
if (this.props.isError) {
throw new Error(
@@ -119,6 +127,7 @@ GUI.propTypes = {
onStorageInit: PropTypes.func,
onUpdateProjectId: PropTypes.func,
onUpdateProjectTitle: PropTypes.func,
onUpdateReduxDeck: PropTypes.func,
onUpdateReduxProjectTitle: PropTypes.func,
previewInfoVisible: PropTypes.bool,
projectHost: PropTypes.string,
@@ -169,6 +178,7 @@ const mapDispatchToProps = dispatch => ({
onActivateSoundsTab: () => dispatch(activateTab(SOUNDS_TAB_INDEX)),
onRequestCloseBackdropLibrary: () => dispatch(closeBackdropLibrary()),
onRequestCloseCostumeLibrary: () => dispatch(closeCostumeLibrary()),
onUpdateReduxDeck: tutorialId => dispatch(activateDeck(tutorialId)),
onUpdateReduxProjectTitle: title => dispatch(setProjectTitle(title))
});
+2 -5
View File
@@ -1,7 +1,6 @@
import GUI from './containers/gui.jsx';
import AppStateHOC from './lib/app-state-hoc.jsx';
import {detectTutorialId} from './lib/tutorial-from-url';
import GuiReducer, {guiInitialState, guiMiddleware, initFullScreen, initPlayer, initTutorialCard} from './reducers/gui';
import GuiReducer, {guiInitialState, guiMiddleware, initFullScreen, initPlayer} from './reducers/gui';
import LocalesReducer, {localesInitialState, initLocale} from './reducers/locales';
import {ScratchPaintReducer} from 'scratch-paint';
import {setFullScreen, setPlayer} from './reducers/mode';
@@ -25,7 +24,5 @@ export {
initLocale,
localesInitialState,
setFullScreen,
setPlayer,
detectTutorialId,
initTutorialCard
setPlayer
};
+4 -11
View File
@@ -52,7 +52,6 @@ const AppStateHOC = function (WrappedComponent, localesOnly) {
guiMiddleware,
initFullScreen,
initPlayer,
initTutorialCard,
initTutorialLibrary
} = guiRedux;
const {ScratchPaintReducer} = require('scratch-paint');
@@ -67,16 +66,10 @@ const AppStateHOC = function (WrappedComponent, localesOnly) {
}
} else {
const tutorialId = detectTutorialId();
if (tutorialId !== null) {
// When loading a tutorial from the URL,
// load w/o preview modal
// open requested tutorial card or tutorials library modal for 'all'
if (tutorialId === 'all') {
initializedGui = initTutorialLibrary(initializedGui);
} else {
initializedGui = initTutorialCard(initializedGui, tutorialId);
}
}
// handle ?tutorial=all for beta
// if we decide to keep this for www, functionality should move to
// setActiveCards in the GUI container
if (tutorialId === 'all') initializedGui = initTutorialLibrary(initializedGui);
}
reducers = {
locales: localesReducer,