Skip to content

Commit f0bd9ef

Browse files
authored
Merge pull request #1628 from ZenVega/develop
Connect the <PreviewFrame /> Component
2 parents e1e9cb9 + e834920 commit f0bd9ef

File tree

2 files changed

+42
-30
lines changed

2 files changed

+42
-30
lines changed

client/modules/IDE/components/PreviewFrame.jsx

Lines changed: 41 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,13 @@ import { hijackConsoleErrorsScript, startTag, getAllScriptOffsets }
2123
from '../../../utils/consoleUtils';
2224
import { registerFrame } from '../../../utils/dispatcher';
2325

26+
import { getHTMLFile } from '../reducers/files';
27+
28+
import { stopSketch, expandConsole, endSketchRefresh } from '../actions/ide';
29+
import { setTextOutput, setGridOutput, setSoundOutput } from '../actions/preferences';
30+
import { setBlobUrl } from '../actions/files';
31+
import { clearConsole, dispatchConsoleEvent } from '../actions/console';
32+
2433

2534
const shouldRenderSketch = (props, prevProps = undefined) => {
2635
const { isPlaying, previewIsRefreshing, fullView } = props;
@@ -350,4 +359,35 @@ PreviewFrame.defaultProps = {
350359
cmController: {}
351360
};
352361

353-
export default PreviewFrame;
362+
const mapStateToProps = state => ({
363+
files: state.files,
364+
htmlFile: getHTMLFile(state.files),
365+
content:
366+
(state.files.find(file => file.isSelectedFile) ||
367+
state.files.find(file => file.name === 'sketch.js') ||
368+
state.files.find(file => file.name !== 'root')).content,
369+
isPlaying: state.ide.isPlaying,
370+
isAccessibleOutputPlaying: state.ide.isAccessibleOutputPlaying,
371+
previewIsRefreshing: state.ide.previewIsRefreshing,
372+
textOutput: state.preferences.textOutput,
373+
gridOutput: state.preferences.gridOutput,
374+
soundOutput: state.preferences.soundOutput,
375+
language: state.preferences.language,
376+
autorefresh: state.preferences.autorefresh,
377+
});
378+
379+
380+
const mapDispatchToProps = {
381+
stopSketch,
382+
expandConsole,
383+
endSketchRefresh,
384+
setTextOutput,
385+
setGridOutput,
386+
setSoundOutput,
387+
setBlobUrl,
388+
clearConsole,
389+
dispatchConsoleEvent
390+
};
391+
392+
393+
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 cmController={this.cmController} />
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)