Skip to content

Commit dcf5d26

Browse files
committed
refactor PreviewFrame by including mapStateToProps and mapDispatchToProps
1 parent 1c27a49 commit dcf5d26

File tree

2 files changed

+55
-30
lines changed

2 files changed

+55
-30
lines changed

client/modules/IDE/components/PreviewFrame.jsx

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import loopProtect from 'loop-protect';
77
import { JSHINT } from 'jshint';
88
import decomment from 'decomment';
99
import classNames from 'classnames';
10+
import { bindActionCreators } from 'redux';
11+
import { connect } from 'react-redux';
1012
import { getBlobUrl } from '../actions/files';
1113
import { resolvePathToFile } from '../../../../server/utils/filePath';
1214
import {
@@ -21,6 +23,18 @@ import { hijackConsoleErrorsScript, startTag, getAllScriptOffsets }
2123
from '../../../utils/consoleUtils';
2224
import { registerFrame } from '../../../utils/dispatcher';
2325

26+
import { getHTMLFile } from '../reducers/files';
27+
import { getIsUserOwner } from '../selectors/users';
28+
29+
import * as FileActions from '../actions/files';
30+
import * as IDEActions from '../actions/ide';
31+
import * as ProjectActions from '../actions/project';
32+
import * as EditorAccessibilityActions from '../actions/editorAccessibility';
33+
import * as PreferencesActions from '../actions/preferences';
34+
import * as UserActions from '../../User/actions';
35+
import * as ToastActions from '../actions/toast';
36+
import * as ConsoleActions from '../actions/console';
37+
2438

2539
const shouldRenderSketch = (props, prevProps = undefined) => {
2640
const { isPlaying, previewIsRefreshing, fullView } = props;
@@ -350,4 +364,43 @@ PreviewFrame.defaultProps = {
350364
cmController: {}
351365
};
352366

353-
export default PreviewFrame;
367+
const mapStateToProps = state => ({
368+
files: state.files,
369+
file:
370+
state.files.find(file => file.isSelectedFile) ||
371+
state.files.find(file => file.name === 'sketch.js') ||
372+
state.files.find(file => file.name !== 'root'),
373+
htmlFile: getHTMLFile(state.files),
374+
ide: state.ide,
375+
preferences: state.preferences,
376+
editorAccessibility: state.editorAccessibility,
377+
user: state.user,
378+
project: state.project,
379+
toast: state.toast,
380+
console: state.console,
381+
382+
...state.preferences,
383+
...state.ide,
384+
...state.project,
385+
...state.editorAccessibility,
386+
isExpanded: state.ide.sidebarIsExpanded,
387+
projectSavedTime: state.project.updatedAt,
388+
isUserOwner: getIsUserOwner(state)
389+
});
390+
391+
const mapDispatchToProps = dispatch => bindActionCreators(
392+
Object.assign(
393+
{},
394+
EditorAccessibilityActions,
395+
FileActions,
396+
ProjectActions,
397+
IDEActions,
398+
PreferencesActions,
399+
UserActions,
400+
ToastActions,
401+
ConsoleActions
402+
),
403+
dispatch
404+
);
405+
406+
export default (connect(mapStateToProps, mapDispatchToProps)(PreviewFrame));

client/modules/IDE/pages/IDEView.jsx

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -363,31 +363,7 @@ class IDEView extends React.Component {
363363
this.props.ide.isPlaying) ||
364364
this.props.ide.isAccessibleOutputPlaying}
365365
</div>
366-
<PreviewFrame
367-
htmlFile={this.props.htmlFile}
368-
files={this.props.files}
369-
content={this.props.selectedFile.content}
370-
isPlaying={this.props.ide.isPlaying}
371-
isAccessibleOutputPlaying={
372-
this.props.ide.isAccessibleOutputPlaying
373-
}
374-
textOutput={this.props.preferences.textOutput}
375-
gridOutput={this.props.preferences.gridOutput}
376-
soundOutput={this.props.preferences.soundOutput}
377-
setTextOutput={this.props.setTextOutput}
378-
setGridOutput={this.props.setGridOutput}
379-
setSoundOutput={this.props.setSoundOutput}
380-
dispatchConsoleEvent={this.props.dispatchConsoleEvent}
381-
autorefresh={this.props.preferences.autorefresh}
382-
previewIsRefreshing={this.props.ide.previewIsRefreshing}
383-
endSketchRefresh={this.props.endSketchRefresh}
384-
stopSketch={this.props.stopSketch}
385-
setBlobUrl={this.props.setBlobUrl}
386-
expandConsole={this.props.expandConsole}
387-
clearConsole={this.props.clearConsole}
388-
cmController={this.cmController}
389-
language={this.props.preferences.language}
390-
/>
366+
<PreviewFrame />
391367
</div>
392368
</section>
393369
</SplitPane>
@@ -566,7 +542,6 @@ IDEView.propTypes = {
566542
name: PropTypes.string.isRequired,
567543
content: PropTypes.string.isRequired,
568544
}).isRequired,
569-
dispatchConsoleEvent: PropTypes.func.isRequired,
570545
newFile: PropTypes.func.isRequired,
571546
expandSidebar: PropTypes.func.isRequired,
572547
collapseSidebar: PropTypes.func.isRequired,
@@ -592,10 +567,7 @@ IDEView.propTypes = {
592567
}).isRequired,
593568
route: PropTypes.oneOfType([PropTypes.object, PropTypes.element]).isRequired,
594569
setTheme: PropTypes.func.isRequired,
595-
endSketchRefresh: PropTypes.func.isRequired,
596-
setBlobUrl: PropTypes.func.isRequired,
597570
setPreviousPath: PropTypes.func.isRequired,
598-
clearConsole: PropTypes.func.isRequired,
599571
showErrorModal: PropTypes.func.isRequired,
600572
hideErrorModal: PropTypes.func.isRequired,
601573
clearPersistedState: PropTypes.func.isRequired,

0 commit comments

Comments
 (0)