re-refactor after fixing merge conflicts
This commit is contained in:
1 parent
abf93ed10a
commit
fdfd9d64f2
4 files changed
+28
-41
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
Reference in new issue
Block a user