diff --git a/src/lib/app-state-hoc.jsx b/src/lib/app-state-hoc.jsx index 4387e0653cac7d58769d3d6ba879101718235c65..495a667d2d0d0c6a9a08afe037368eb1ccd05e34 100644 --- a/src/lib/app-state-hoc.jsx +++ b/src/lib/app-state-hoc.jsx @@ -10,7 +10,6 @@ import {setPlayer, setFullScreen} from '../reducers/mode.js'; import locales from 'scratch-l10n'; import {detectLocale} from './detect-locale'; -import {detectTutorialId} from './tutorial-from-url'; const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; @@ -65,11 +64,7 @@ const AppStateHOC = function (WrappedComponent, localesOnly) { initializedGui = initPlayer(initializedGui); } } else { - const tutorialId = detectTutorialId(); - if (tutorialId === null && props.showPreviewInfo) { - // Show preview info if requested and no tutorial ID found - initializedGui = initPreviewInfo(initializedGui); - } + initializedGui = initPreviewInfo(initializedGui); } reducers = { locales: localesReducer, diff --git a/src/lib/query-parser-hoc.jsx b/src/lib/query-parser-hoc.jsx index e23d4caa1f1527c24b7967e6d0c9f4a1c81693dc..161b1a34aeee5218818dd714c2405703f2879111 100644 --- a/src/lib/query-parser-hoc.jsx +++ b/src/lib/query-parser-hoc.jsx @@ -6,7 +6,7 @@ import {connect} from 'react-redux'; import {detectTutorialId} from './tutorial-from-url'; import {activateDeck} from '../reducers/cards'; -import {openTipsLibrary} from '../reducers/modals'; +import {openTipsLibrary, closePreviewInfo} from '../reducers/modals'; /* Higher Order Component to get parameters from the URL query string and initialize redux state * @param {React.Component} WrappedComponent: component to render @@ -17,13 +17,8 @@ const QueryParserHOC = function (WrappedComponent) { constructor (props) { super(props); const queryParams = queryString.parse(location.search); - this.state = { - tutorial: false - }; - const tutorialId = detectTutorialId(queryParams); if (tutorialId) { - this.state.tutorial = true; if (tutorialId === 'all') { this.openTutorials(); } else { @@ -39,11 +34,10 @@ const QueryParserHOC = function (WrappedComponent) { } render () { const { - hideIntro: hideIntroProp, + onOpenTipsLibrary, // eslint-disable-line no-unused-vars + onUpdateReduxDeck, // eslint-disable-line no-unused-vars ...componentProps } = this.props; - // override hideIntro if there is a tutorial - componentProps.hideIntro = this.state.tutorial || hideIntroProp; return ( <WrappedComponent {...componentProps} @@ -52,13 +46,18 @@ const QueryParserHOC = function (WrappedComponent) { } } QueryParserComponent.propTypes = { - hideIntro: PropTypes.bool, onOpenTipsLibrary: PropTypes.func, onUpdateReduxDeck: PropTypes.func }; const mapDispatchToProps = dispatch => ({ - onOpenTipsLibrary: () => dispatch(openTipsLibrary()), - onUpdateReduxDeck: tutorialId => dispatch(activateDeck(tutorialId)) + onOpenTipsLibrary: () => { + dispatch(openTipsLibrary()); + dispatch(closePreviewInfo()); + }, + onUpdateReduxDeck: tutorialId => { + dispatch(activateDeck(tutorialId)); + dispatch(closePreviewInfo()); + } }); return connect( null, diff --git a/src/lib/tutorial-from-url.js b/src/lib/tutorial-from-url.js index fb2df2642980db23872153df964fcb738865d939..5e601fe33e96fcb89d4e383b2e5d83987d9f4ab4 100644 --- a/src/lib/tutorial-from-url.js +++ b/src/lib/tutorial-from-url.js @@ -5,7 +5,6 @@ import tutorials from './libraries/decks/index.jsx'; import analytics from './analytics'; -import queryString from 'query-string'; /** * Get the tutorial id from the given numerical id (representing the @@ -35,8 +34,7 @@ const getDeckIdFromUrlId = urlId => { * @return {string} The ID of the requested tutorial or null if no tutorial was * requested or found. */ -const detectTutorialId = () => { - const queryParams = queryString.parse(location.search); +const detectTutorialId = queryParams => { const tutorialID = Array.isArray(queryParams.tutorial) ? queryParams.tutorial[0] : queryParams.tutorial; diff --git a/test/unit/util/tutorial-from-url.test.js b/test/unit/util/tutorial-from-url.test.js index cfe2c14fe2acb0ea25fb3bf2b8552e1a8ae17b67..454bc8725c9374ed8aa05d2121dcc4ba277aa03d 100644 --- a/test/unit/util/tutorial-from-url.test.js +++ b/test/unit/util/tutorial-from-url.test.js @@ -8,45 +8,40 @@ jest.mock('../../../src/lib/libraries/decks/index.jsx', () => ({ noUrlIdSandwich: {} })); +import queryString from 'query-string'; import {detectTutorialId} from '../../../src/lib/tutorial-from-url.js'; -Object.defineProperty( - window.location, - 'search', - {value: '', writable: true} -); - test('returns the tutorial ID if the urlId matches', () => { - window.location.search = '?tutorial=one'; - expect(detectTutorialId()).toBe('foo'); + const queryParams = queryString.parse('?tutorial=one'); + expect(detectTutorialId(queryParams)).toBe('foo'); }); test('returns null if no matching urlId', () => { - window.location.search = '?tutorial=10'; - expect(detectTutorialId()).toBe(null); + const queryParams = queryString.parse('?tutorial=10'); + expect(detectTutorialId(queryParams)).toBe(null); }); test('returns null if empty template', () => { - window.location.search = '?tutorial='; - expect(detectTutorialId()).toBe(null); + const queryParams = queryString.parse('?tutorial='); + expect(detectTutorialId(queryParams)).toBe(null); }); test('returns null if no query param', () => { - window.location.search = ''; - expect(detectTutorialId()).toBe(null); + const queryParams = queryString.parse(''); + expect(detectTutorialId(queryParams)).toBe(null); }); test('returns null if unrecognized template', () => { - window.location.search = '?tutorial=asdf'; - expect(detectTutorialId()).toBe(null); + const queryParams = queryString.parse('?tutorial=asdf'); + expect(detectTutorialId(queryParams)).toBe(null); }); test('takes the first of multiple', () => { - window.location.search = '?tutorial=one&tutorial=two'; - expect(detectTutorialId()).toBe('foo'); + const queryParams = queryString.parse('?tutorial=one&tutorial=two'); + expect(detectTutorialId(queryParams)).toBe('foo'); }); test('returns all for the tutorial library shortcut', () => { - window.location.search = '?tutorial=all'; - expect(detectTutorialId()).toBe('all'); + const queryParams = queryString.parse('?tutorial=all'); + expect(detectTutorialId(queryParams)).toBe('all'); });