Skip to content

Commit 7d00d3d

Browse files
committed
Remove the hideIntro override and default preview modal to false
The use of an "override" prop that allowed the preview modal to be hidden without actually changing the redux state was causing a problem where the block editors where not closing when modals were opening. That is because it relied on the modal reducer being accurate. I defaulted the preview state to false to make it simpler to consume the GUI, as www will not want the preview info to be true. I made it true in the playground instead. This fixes #3710
1 parent 0cf5b1f commit 7d00d3d

File tree

6 files changed

+35
-19
lines changed

6 files changed

+35
-19
lines changed

src/containers/gui.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class GUI extends React.Component {
7575
assetHost,
7676
cloudHost,
7777
error,
78-
hideIntro,
7978
isError,
8079
isShowingProject,
8180
onStorageInit,
@@ -108,7 +107,6 @@ GUI.propTypes = {
108107
cloudHost: PropTypes.string,
109108
error: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
110109
fetchingProject: PropTypes.bool,
111-
hideIntro: PropTypes.bool,
112110
importInfoVisible: PropTypes.bool,
113111
intl: intlShape,
114112
isError: PropTypes.bool,
@@ -132,7 +130,7 @@ GUI.defaultProps = {
132130
onUpdateProjectId: () => {}
133131
};
134132

135-
const mapStateToProps = (state, ownProps) => {
133+
const mapStateToProps = state => {
136134
const loadingState = state.scratchGui.projectState.loadingState;
137135
return {
138136
activeTabIndex: state.scratchGui.editorTab.activeTabIndex,
@@ -150,7 +148,7 @@ const mapStateToProps = (state, ownProps) => {
150148
isRtl: state.locales.isRtl,
151149
isShowingProject: getIsShowingProject(loadingState),
152150
loadingStateVisible: state.scratchGui.modals.loadingProject,
153-
previewInfoVisible: state.scratchGui.modals.previewInfo && !ownProps.hideIntro,
151+
previewInfoVisible: state.scratchGui.modals.previewInfo,
154152
projectId: state.scratchGui.projectState.projectId,
155153
targetIsStage: (
156154
state.scratchGui.targets.stage &&

src/lib/app-state-hoc.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ const AppStateHOC = function (WrappedComponent, localesOnly) {
5353
initFullScreen,
5454
initPlayer,
5555
initTutorialCard,
56-
initTutorialLibrary
56+
initTutorialLibrary,
57+
initPreviewInfo
5758
} = guiRedux;
5859
const {ScratchPaintReducer} = require('scratch-paint');
5960

@@ -76,6 +77,9 @@ const AppStateHOC = function (WrappedComponent, localesOnly) {
7677
} else {
7778
initializedGui = initTutorialCard(initializedGui, tutorialId);
7879
}
80+
} else if (props.showPreviewInfo) {
81+
// Show preview info if requested and no tutorial ID found
82+
initializedGui = initPreviewInfo(initializedGui);
7983
}
8084
}
8185
reducers = {
@@ -109,6 +113,7 @@ const AppStateHOC = function (WrappedComponent, localesOnly) {
109113
const {
110114
isFullScreen, // eslint-disable-line no-unused-vars
111115
isPlayerOnly, // eslint-disable-line no-unused-vars
116+
showPreviewInfo, // eslint-disable-line no-unused-vars
112117
...componentProps
113118
} = this.props;
114119
return (
@@ -122,7 +127,8 @@ const AppStateHOC = function (WrappedComponent, localesOnly) {
122127
}
123128
AppStateWrapper.propTypes = {
124129
isFullScreen: PropTypes.bool,
125-
isPlayerOnly: PropTypes.bool
130+
isPlayerOnly: PropTypes.bool,
131+
showPreviewInfo: PropTypes.bool
126132
};
127133
return AppStateWrapper;
128134
};

src/lib/hash-parser-hoc.jsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import {
99
setProjectId
1010
} from '../reducers/project-state';
1111

12+
import {
13+
closePreviewInfo
14+
} from '../reducers/modals';
15+
1216
/* Higher Order Component to get the project id from location.hash
1317
* @param {React.Component} WrappedComponent: component to render
1418
* @returns {React.Component} component with hash parsing behavior
@@ -20,9 +24,6 @@ const HashParserHOC = function (WrappedComponent) {
2024
bindAll(this, [
2125
'handleHashChange'
2226
]);
23-
this.state = {
24-
hideIntro: false
25-
};
2627
}
2728
componentDidMount () {
2829
window.addEventListener('hashchange', this.handleHashChange);
@@ -43,9 +44,6 @@ const HashParserHOC = function (WrappedComponent) {
4344
const hashMatch = window.location.hash.match(/#(\d+)/);
4445
const hashProjectId = hashMatch === null ? defaultProjectId : hashMatch[1];
4546
this.props.setProjectId(hashProjectId.toString());
46-
if (hashProjectId !== defaultProjectId) {
47-
this.setState({hideIntro: true});
48-
}
4947
}
5048
render () {
5149
const {
@@ -58,7 +56,6 @@ const HashParserHOC = function (WrappedComponent) {
5856
} = this.props;
5957
return (
6058
<WrappedComponent
61-
hideIntro={this.state.hideIntro}
6259
{...componentProps}
6360
/>
6461
);
@@ -77,7 +74,12 @@ const HashParserHOC = function (WrappedComponent) {
7774
};
7875
};
7976
const mapDispatchToProps = dispatch => ({
80-
setProjectId: projectId => dispatch(setProjectId(projectId))
77+
setProjectId: projectId => {
78+
dispatch(setProjectId(projectId));
79+
if (projectId !== defaultProjectId) {
80+
dispatch(closePreviewInfo());
81+
}
82+
}
8183
});
8284
// Allow incoming props to override redux-provided props. Used to mock in tests.
8385
const mergeProps = (stateProps, dispatchProps, ownProps) => Object.assign(

src/playground/render-gui.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export default appTarget => {
3737
<WrappedGui
3838
backpackVisible
3939
showComingSoon
40+
showPreviewInfo
4041
backpackHost={backpackHost}
4142
/>,
4243
appTarget);

src/reducers/gui.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ const initTutorialCard = function (currentState, deckId) {
8080
{},
8181
currentState,
8282
{
83-
modals: {
84-
previewInfo: false
85-
},
8683
cards: {
8784
visible: true,
8885
content: decks,
@@ -102,13 +99,24 @@ const initTutorialLibrary = function (currentState) {
10299
currentState,
103100
{
104101
modals: {
105-
previewInfo: false,
106102
tipsLibrary: true
107103
}
108104
}
109105
);
110106
};
111107

108+
const initPreviewInfo = function (currentState) {
109+
return Object.assign(
110+
{},
111+
currentState,
112+
{
113+
modals: {
114+
previewInfo: true
115+
}
116+
}
117+
);
118+
};
119+
112120
const guiReducer = combineReducers({
113121
alerts: alertsReducer,
114122
assetDrag: assetDragReducer,
@@ -141,6 +149,7 @@ export {
141149
guiMiddleware,
142150
initFullScreen,
143151
initPlayer,
152+
initPreviewInfo,
144153
initTutorialCard,
145154
initTutorialLibrary
146155
};

src/reducers/modals.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const initialState = {
2323
[MODAL_EXTENSION_LIBRARY]: false,
2424
[MODAL_IMPORT_INFO]: false,
2525
[MODAL_LOADING_PROJECT]: false,
26-
[MODAL_PREVIEW_INFO]: true,
26+
[MODAL_PREVIEW_INFO]: false,
2727
[MODAL_SOUND_LIBRARY]: false,
2828
[MODAL_SPRITE_LIBRARY]: false,
2929
[MODAL_SOUND_RECORDER]: false,

0 commit comments

Comments
 (0)