Skip to content

Commit fdfd9d6

Browse files
committed
re-refactor after fixing merge conflicts
1 parent abf93ed commit fdfd9d6

File tree

4 files changed

+28
-41
lines changed

4 files changed

+28
-41
lines changed

src/lib/app-state-hoc.jsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {setPlayer, setFullScreen} from '../reducers/mode.js';
1010

1111
import locales from 'scratch-l10n';
1212
import {detectLocale} from './detect-locale';
13-
import {detectTutorialId} from './tutorial-from-url';
1413

1514
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
1615

@@ -65,11 +64,7 @@ const AppStateHOC = function (WrappedComponent, localesOnly) {
6564
initializedGui = initPlayer(initializedGui);
6665
}
6766
} else {
68-
const tutorialId = detectTutorialId();
69-
if (tutorialId === null && props.showPreviewInfo) {
70-
// Show preview info if requested and no tutorial ID found
71-
initializedGui = initPreviewInfo(initializedGui);
72-
}
67+
initializedGui = initPreviewInfo(initializedGui);
7368
}
7469
reducers = {
7570
locales: localesReducer,

src/lib/query-parser-hoc.jsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {connect} from 'react-redux';
66
import {detectTutorialId} from './tutorial-from-url';
77

88
import {activateDeck} from '../reducers/cards';
9-
import {openTipsLibrary} from '../reducers/modals';
9+
import {openTipsLibrary, closePreviewInfo} from '../reducers/modals';
1010

1111
/* Higher Order Component to get parameters from the URL query string and initialize redux state
1212
* @param {React.Component} WrappedComponent: component to render
@@ -17,13 +17,8 @@ const QueryParserHOC = function (WrappedComponent) {
1717
constructor (props) {
1818
super(props);
1919
const queryParams = queryString.parse(location.search);
20-
this.state = {
21-
tutorial: false
22-
};
23-
2420
const tutorialId = detectTutorialId(queryParams);
2521
if (tutorialId) {
26-
this.state.tutorial = true;
2722
if (tutorialId === 'all') {
2823
this.openTutorials();
2924
} else {
@@ -39,11 +34,10 @@ const QueryParserHOC = function (WrappedComponent) {
3934
}
4035
render () {
4136
const {
42-
hideIntro: hideIntroProp,
37+
onOpenTipsLibrary, // eslint-disable-line no-unused-vars
38+
onUpdateReduxDeck, // eslint-disable-line no-unused-vars
4339
...componentProps
4440
} = this.props;
45-
// override hideIntro if there is a tutorial
46-
componentProps.hideIntro = this.state.tutorial || hideIntroProp;
4741
return (
4842
<WrappedComponent
4943
{...componentProps}
@@ -52,13 +46,18 @@ const QueryParserHOC = function (WrappedComponent) {
5246
}
5347
}
5448
QueryParserComponent.propTypes = {
55-
hideIntro: PropTypes.bool,
5649
onOpenTipsLibrary: PropTypes.func,
5750
onUpdateReduxDeck: PropTypes.func
5851
};
5952
const mapDispatchToProps = dispatch => ({
60-
onOpenTipsLibrary: () => dispatch(openTipsLibrary()),
61-
onUpdateReduxDeck: tutorialId => dispatch(activateDeck(tutorialId))
53+
onOpenTipsLibrary: () => {
54+
dispatch(openTipsLibrary());
55+
dispatch(closePreviewInfo());
56+
},
57+
onUpdateReduxDeck: tutorialId => {
58+
dispatch(activateDeck(tutorialId));
59+
dispatch(closePreviewInfo());
60+
}
6261
});
6362
return connect(
6463
null,

src/lib/tutorial-from-url.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import tutorials from './libraries/decks/index.jsx';
77
import analytics from './analytics';
8-
import queryString from 'query-string';
98

109
/**
1110
* Get the tutorial id from the given numerical id (representing the
@@ -35,8 +34,7 @@ const getDeckIdFromUrlId = urlId => {
3534
* @return {string} The ID of the requested tutorial or null if no tutorial was
3635
* requested or found.
3736
*/
38-
const detectTutorialId = () => {
39-
const queryParams = queryString.parse(location.search);
37+
const detectTutorialId = queryParams => {
4038
const tutorialID = Array.isArray(queryParams.tutorial) ?
4139
queryParams.tutorial[0] :
4240
queryParams.tutorial;

test/unit/util/tutorial-from-url.test.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,40 @@ jest.mock('../../../src/lib/libraries/decks/index.jsx', () => ({
88
noUrlIdSandwich: {}
99
}));
1010

11+
import queryString from 'query-string';
1112
import {detectTutorialId} from '../../../src/lib/tutorial-from-url.js';
1213

13-
Object.defineProperty(
14-
window.location,
15-
'search',
16-
{value: '', writable: true}
17-
);
18-
1914
test('returns the tutorial ID if the urlId matches', () => {
20-
window.location.search = '?tutorial=one';
21-
expect(detectTutorialId()).toBe('foo');
15+
const queryParams = queryString.parse('?tutorial=one');
16+
expect(detectTutorialId(queryParams)).toBe('foo');
2217
});
2318

2419
test('returns null if no matching urlId', () => {
25-
window.location.search = '?tutorial=10';
26-
expect(detectTutorialId()).toBe(null);
20+
const queryParams = queryString.parse('?tutorial=10');
21+
expect(detectTutorialId(queryParams)).toBe(null);
2722
});
2823

2924
test('returns null if empty template', () => {
30-
window.location.search = '?tutorial=';
31-
expect(detectTutorialId()).toBe(null);
25+
const queryParams = queryString.parse('?tutorial=');
26+
expect(detectTutorialId(queryParams)).toBe(null);
3227
});
3328

3429
test('returns null if no query param', () => {
35-
window.location.search = '';
36-
expect(detectTutorialId()).toBe(null);
30+
const queryParams = queryString.parse('');
31+
expect(detectTutorialId(queryParams)).toBe(null);
3732
});
3833

3934
test('returns null if unrecognized template', () => {
40-
window.location.search = '?tutorial=asdf';
41-
expect(detectTutorialId()).toBe(null);
35+
const queryParams = queryString.parse('?tutorial=asdf');
36+
expect(detectTutorialId(queryParams)).toBe(null);
4237
});
4338

4439
test('takes the first of multiple', () => {
45-
window.location.search = '?tutorial=one&tutorial=two';
46-
expect(detectTutorialId()).toBe('foo');
40+
const queryParams = queryString.parse('?tutorial=one&tutorial=two');
41+
expect(detectTutorialId(queryParams)).toBe('foo');
4742
});
4843

4944
test('returns all for the tutorial library shortcut', () => {
50-
window.location.search = '?tutorial=all';
51-
expect(detectTutorialId()).toBe('all');
45+
const queryParams = queryString.parse('?tutorial=all');
46+
expect(detectTutorialId(queryParams)).toBe('all');
5247
});

0 commit comments

Comments
 (0)