Skip to content

Commit 682db4d

Browse files
committed
♻️ connect <Editor />
1 parent 7402a6b commit 682db4d

File tree

2 files changed

+64
-75
lines changed

2 files changed

+64
-75
lines changed

client/modules/IDE/components/Editor.jsx

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import { CSSLint } from 'csslint';
2626
import { HTMLHint } from 'htmlhint';
2727
import classNames from 'classnames';
2828
import { debounce } from 'lodash';
29+
import { connect } from 'react-redux';
30+
import { bindActionCreators } from 'redux';
2931
import '../../../utils/htmlmixed';
3032
import '../../../utils/p5-javascript';
3133
import '../../../utils/webGL-clike';
@@ -39,6 +41,16 @@ import beepUrl from '../../../sounds/audioAlert.mp3';
3941
import UnsavedChangesDotIcon from '../../../images/unsaved-changes-dot.svg';
4042
import RightArrowIcon from '../../../images/right-arrow.svg';
4143
import LeftArrowIcon from '../../../images/left-arrow.svg';
44+
import { getHTMLFile } from '../reducers/files';
45+
46+
import * as FileActions from '../actions/files';
47+
import * as IDEActions from '../actions/ide';
48+
import * as ProjectActions from '../actions/project';
49+
import * as EditorAccessibilityActions from '../actions/editorAccessibility';
50+
import * as PreferencesActions from '../actions/preferences';
51+
import * as UserActions from '../../User/actions';
52+
import * as ToastActions from '../actions/toast';
53+
import * as ConsoleActions from '../actions/console';
4254

4355
search(CodeMirror);
4456

@@ -411,4 +423,47 @@ Editor.defaultProps = {
411423
consoleEvents: [],
412424
};
413425

414-
export default Editor;
426+
427+
function mapStateToProps(state) {
428+
return {
429+
files: state.files,
430+
file:
431+
state.files.find(file => file.isSelectedFile) ||
432+
state.files.find(file => file.name === 'sketch.js') ||
433+
state.files.find(file => file.name !== 'root'),
434+
htmlFile: getHTMLFile(state.files),
435+
ide: state.ide,
436+
preferences: state.preferences,
437+
editorAccessibility: state.editorAccessibility,
438+
user: state.user,
439+
project: state.project,
440+
toast: state.toast,
441+
console: state.console,
442+
443+
...state.preferences,
444+
...state.ide,
445+
...state.project,
446+
...state.editorAccessibility,
447+
isExpanded: state.ide.consoleIsExpanded,
448+
projectSavedTime: state.project.updatedAt
449+
};
450+
}
451+
452+
function mapDispatchToProps(dispatch) {
453+
return bindActionCreators(
454+
Object.assign(
455+
{},
456+
EditorAccessibilityActions,
457+
FileActions,
458+
ProjectActions,
459+
IDEActions,
460+
PreferencesActions,
461+
UserActions,
462+
ToastActions,
463+
ConsoleActions
464+
),
465+
dispatch
466+
);
467+
}
468+
469+
export default connect(mapStateToProps, mapDispatchToProps)(Editor);

client/modules/IDE/pages/MobileIDEView.jsx

Lines changed: 8 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,14 @@ const getNatOptions = (username = undefined) =>
7474

7575
const MobileIDEView = (props) => {
7676
const {
77-
preferences, ide, editorAccessibility, project, updateLintMessage, clearLintMessage,
78-
selectedFile, updateFileContent, files, user, params,
79-
closeEditorOptions, showEditorOptions, unsavedChanges,
80-
startRefreshSketch, stopSketch, expandSidebar, collapseSidebar, clearConsole, console,
81-
showRuntimeErrorWarning, hideRuntimeErrorWarning, startSketch, getProject, clearPersistedState
77+
ide, project, selectedFile, user, params,
78+
stopSketch, startSketch, getProject, clearPersistedState
8279
} = props;
8380

8481
const [tmController, setTmController] = useState(null); // eslint-disable-line
8582

8683
const { username } = user;
84+
const { unsavedChanges } = ide;
8785

8886
const [triggerNavDropdown, NavDropDown] = useAsModal(<Dropdown
8987
items={getNatOptions(username)}
@@ -127,38 +125,7 @@ const MobileIDEView = (props) => {
127125
</Header>
128126

129127
<IDEWrapper>
130-
<Editor
131-
lintWarning={preferences.lintWarning}
132-
linewrap={preferences.linewrap}
133-
lintMessages={editorAccessibility.lintMessages}
134-
updateLintMessage={updateLintMessage}
135-
clearLintMessage={clearLintMessage}
136-
file={selectedFile}
137-
updateFileContent={updateFileContent}
138-
fontSize={preferences.fontSize}
139-
lineNumbers={preferences.lineNumbers}
140-
files={files}
141-
editorOptionsVisible={ide.editorOptionsVisible}
142-
showEditorOptions={showEditorOptions}
143-
closeEditorOptions={closeEditorOptions}
144-
showKeyboard={ide.isPlaying}
145-
theme={preferences.theme}
146-
startRefreshSketch={startRefreshSketch}
147-
stopSketch={stopSketch}
148-
autorefresh={preferences.autorefresh}
149-
unsavedChanges={ide.unsavedChanges}
150-
projectSavedTime={project.updatedAt}
151-
isExpanded={ide.sidebarIsExpanded}
152-
expandSidebar={expandSidebar}
153-
collapseSidebar={collapseSidebar}
154-
isUserOwner={isUserOwner(props)}
155-
clearConsole={clearConsole}
156-
consoleEvents={console}
157-
showRuntimeErrorWarning={showRuntimeErrorWarning}
158-
hideRuntimeErrorWarning={hideRuntimeErrorWarning}
159-
runtimeErrorWarningVisible={ide.runtimeErrorWarningVisible}
160-
provideController={setTmController}
161-
/>
128+
<Editor provideController={setTmController} />
162129
</IDEWrapper>
163130

164131
<Footer>
@@ -203,7 +170,6 @@ MobileIDEView.propTypes = {
203170
shareModalProjectUsername: PropTypes.string.isRequired,
204171
editorOptionsVisible: PropTypes.bool.isRequired,
205172
keyboardShortcutVisible: PropTypes.bool.isRequired,
206-
unsavedChanges: PropTypes.bool.isRequired,
207173
infiniteLoop: PropTypes.bool.isRequired,
208174
previewIsRefreshing: PropTypes.bool.isRequired,
209175
infiniteLoopMessage: PropTypes.string.isRequired,
@@ -213,6 +179,8 @@ MobileIDEView.propTypes = {
213179
errorType: PropTypes.string,
214180
runtimeErrorWarningVisible: PropTypes.bool.isRequired,
215181
uploadFileModalVisible: PropTypes.bool.isRequired,
182+
183+
unsavedChanges: PropTypes.bool.isRequired,
216184
}).isRequired,
217185

218186
editorAccessibility: PropTypes.shape({
@@ -230,48 +198,15 @@ MobileIDEView.propTypes = {
230198
}).isRequired,
231199

232200
startSketch: PropTypes.func.isRequired,
201+
stopSketch: PropTypes.func.isRequired,
233202

234-
updateLintMessage: PropTypes.func.isRequired,
235-
236-
clearLintMessage: PropTypes.func.isRequired,
237203

238204
selectedFile: PropTypes.shape({
239205
id: PropTypes.string.isRequired,
240206
content: PropTypes.string.isRequired,
241207
name: PropTypes.string.isRequired,
242208
}).isRequired,
243209

244-
updateFileContent: PropTypes.func.isRequired,
245-
246-
files: PropTypes.arrayOf(PropTypes.shape({
247-
id: PropTypes.string.isRequired,
248-
name: PropTypes.string.isRequired,
249-
content: PropTypes.string.isRequired,
250-
})).isRequired,
251-
252-
closeEditorOptions: PropTypes.func.isRequired,
253-
254-
showEditorOptions: PropTypes.func.isRequired,
255-
256-
startRefreshSketch: PropTypes.func.isRequired,
257-
258-
stopSketch: PropTypes.func.isRequired,
259-
260-
expandSidebar: PropTypes.func.isRequired,
261-
262-
collapseSidebar: PropTypes.func.isRequired,
263-
264-
clearConsole: PropTypes.func.isRequired,
265-
266-
console: PropTypes.arrayOf(PropTypes.shape({
267-
method: PropTypes.string.isRequired,
268-
args: PropTypes.arrayOf(PropTypes.string),
269-
})).isRequired,
270-
271-
showRuntimeErrorWarning: PropTypes.func.isRequired,
272-
273-
hideRuntimeErrorWarning: PropTypes.func.isRequired,
274-
275210
user: PropTypes.shape({
276211
authenticated: PropTypes.bool.isRequired,
277212
id: PropTypes.string,
@@ -284,8 +219,6 @@ MobileIDEView.propTypes = {
284219
project_id: PropTypes.string,
285220
username: PropTypes.string
286221
}).isRequired,
287-
288-
unsavedChanges: PropTypes.bool.isRequired
289222
};
290223

291224
function mapStateToProps(state) {
@@ -297,6 +230,7 @@ function mapStateToProps(state) {
297230
state.files.find(file => file.name !== 'root'),
298231
htmlFile: getHTMLFile(state.files),
299232
ide: state.ide,
233+
unsavedChanges: state.ide.unsavedChanged,
300234
preferences: state.preferences,
301235
editorAccessibility: state.editorAccessibility,
302236
user: state.user,

0 commit comments

Comments
 (0)