Skip to content

Commit d3f7d3d

Browse files
committed
♻️ refactor <Console /> to use hooks
2 parents b87a313 + dd15f80 commit d3f7d3d

File tree

7 files changed

+87
-45
lines changed

7 files changed

+87
-45
lines changed

client/components/mobile/Footer.jsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,42 @@
11
import React from 'react';
22
import styled from 'styled-components';
3+
import PropTypes from 'prop-types';
34
import { prop, remSize } from '../../theme';
45

6+
57
const background = prop('MobilePanel.default.background');
68
const textColor = prop('primaryTextColor');
79

8-
const Footer = styled.div`
10+
const FooterWrapper = styled.div`
911
position: fixed;
1012
width: 100%;
13+
bottom: 0;
14+
`;
15+
16+
const FooterContent = styled.div`
1117
background: ${background};
1218
color: ${textColor};
1319
padding: ${remSize(12)};
1420
padding-left: ${remSize(32)};
15-
z-index: 1;
16-
17-
bottom: 0;
1821
`;
1922

23+
const Footer = ({ before, children }) => (
24+
<FooterWrapper>
25+
{before}
26+
<FooterContent>
27+
{children}
28+
</FooterContent>
29+
</FooterWrapper>
30+
);
31+
32+
Footer.propTypes = {
33+
before: PropTypes.element,
34+
children: PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)]),
35+
};
36+
37+
Footer.defaultProps = {
38+
before: <></>,
39+
children: <></>
40+
};
41+
2042
export default Footer;

client/modules/IDE/components/Console.jsx

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
3+
import { bindActionCreators } from 'redux';
4+
5+
import { useSelector, useDispatch } from 'react-redux';
36
import classNames from 'classnames';
47
import { Console as ConsoleFeed } from 'console-feed';
58
import {
@@ -22,7 +25,10 @@ import infoContrastUrl from '../../../images/console-info-contrast.svg?byUrl';
2225
import UpArrowIcon from '../../../images/up-arrow.svg';
2326
import DownArrowIcon from '../../../images/down-arrow.svg';
2427

25-
class Console extends React.Component {
28+
import * as IDEActions from '../../IDE/actions/ide';
29+
import * as ConsoleActions from '../../IDE/actions/console';
30+
31+
class ConsoleComponent extends React.Component {
2632
componentDidUpdate(prevProps) {
2733
this.consoleMessages.scrollTop = this.consoleMessages.scrollHeight;
2834
if (this.props.theme !== prevProps.theme) {
@@ -132,7 +138,7 @@ class Console extends React.Component {
132138
}
133139
}
134140

135-
Console.propTypes = {
141+
ConsoleComponent.propTypes = {
136142
consoleEvents: PropTypes.arrayOf(PropTypes.shape({
137143
method: PropTypes.string.isRequired,
138144
args: PropTypes.arrayOf(PropTypes.string)
@@ -146,8 +152,46 @@ Console.propTypes = {
146152
fontSize: PropTypes.number.isRequired
147153
};
148154

149-
Console.defaultProps = {
155+
ConsoleComponent.defaultProps = {
150156
consoleEvents: []
151157
};
152158

159+
const Console = () => {
160+
const consoleEvents = useSelector(state => state.console);
161+
const { consoleIsExpanded } = useSelector(state => state.ide);
162+
const { theme, fontSize } = useSelector(state => state.preferences);
163+
164+
const {
165+
collapseConsole, expandConsole, clearConsole, dispatchConsoleEvent
166+
} = bindActionCreators({ ...IDEActions, ...ConsoleActions }, useDispatch());
167+
168+
return (
169+
<ConsoleComponent
170+
consoleEvents={consoleEvents}
171+
isExpanded={consoleIsExpanded}
172+
theme={theme}
173+
fontSize={fontSize}
174+
collapseConsole={collapseConsole}
175+
expandConsole={expandConsole}
176+
clearConsole={clearConsole}
177+
dispatchConsoleEvent={dispatchConsoleEvent}
178+
/>
179+
);
180+
};
181+
182+
// const Console = connect(
183+
// state => ({
184+
// consoleEvents: state.console,
185+
// isExpanded: state.ide.consoleIsExpanded,
186+
// theme: state.preferences.theme,
187+
// fontSize: state.preferences.fontSize
188+
// }),
189+
// dispatch => ({
190+
// collapseConsole: () => dispatch(IDEActions.collapseConsole()),
191+
// expandConsole: () => dispatch(IDEActions.expandConsole()),
192+
// clearConsole: () => dispatch(ConsoleActions.clearConsole()),
193+
// dispatchConsoleEvent: msgs => dispatch(ConsoleActions.dispatchConsoleEvent(msgs)),
194+
// })
195+
// )(ConsoleComponent);
196+
153197
export default Console;

client/modules/IDE/pages/IDEView.jsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,7 @@ class IDEView extends React.Component {
324324
runtimeErrorWarningVisible={this.props.ide.runtimeErrorWarningVisible}
325325
provideController={(ctl) => { this.cmController = ctl; }}
326326
/>
327-
<Console
328-
fontSize={this.props.preferences.fontSize}
329-
consoleEvents={this.props.console}
330-
isExpanded={this.props.ide.consoleIsExpanded}
331-
expandConsole={this.props.expandConsole}
332-
collapseConsole={this.props.collapseConsole}
333-
clearConsole={this.props.clearConsole}
334-
dispatchConsoleEvent={this.props.dispatchConsoleEvent}
335-
theme={this.props.preferences.theme}
336-
/>
327+
<Console />
337328
</SplitPane>
338329
<section className="preview-frame-holder">
339330
<header className="preview-frame__header">
@@ -649,6 +640,4 @@ function mapDispatchToProps(dispatch) {
649640
);
650641
}
651642

652-
653643
export default withTranslation('WebEditor')(withRouter(connect(mapStateToProps, mapDispatchToProps)(IDEView)));
654-

client/modules/IDE/pages/MobileIDEView.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
33
import { connect } from 'react-redux';
44
import { withRouter } from 'react-router';
55
import { useState } from 'react';
6+
import styled from 'styled-components';
67

78
// Imports to be Refactored
89
import { bindActionCreators } from 'redux';
@@ -25,6 +26,8 @@ import Header from '../../../components/mobile/Header';
2526
import Screen from '../../../components/mobile/MobileScreen';
2627
import Footer from '../../../components/mobile/Footer';
2728
import IDEWrapper from '../../../components/mobile/IDEWrapper';
29+
import Console from '../components/Console';
30+
import { remSize } from '../../../theme';
2831

2932
const isUserOwner = ({ project, user }) => (project.owner && project.owner.id === user.id);
3033

@@ -94,7 +97,9 @@ const MobileIDEView = (props) => {
9497
provideController={setTmController}
9598
/>
9699
</IDEWrapper>
97-
<Footer><h2>Bottom Bar</h2></Footer>
100+
<Footer before={<Console />} >
101+
<h2>Bottom Bar</h2>
102+
</Footer>
98103
</Screen>
99104
);
100105
};

client/modules/Mobile/MobilePreferences.jsx

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,4 @@ const MobilePreferences = () => {
8989
</Screen>);
9090
};
9191

92-
93-
MobilePreferences.propTypes = {
94-
fontSize: PropTypes.number.isRequired,
95-
lineNumbers: PropTypes.bool.isRequired,
96-
autosave: PropTypes.bool.isRequired,
97-
linewrap: PropTypes.bool.isRequired,
98-
textOutput: PropTypes.bool.isRequired,
99-
gridOutput: PropTypes.bool.isRequired,
100-
soundOutput: PropTypes.bool.isRequired,
101-
lintWarning: PropTypes.bool.isRequired,
102-
theme: PropTypes.string.isRequired,
103-
104-
setLinewrap: PropTypes.func.isRequired,
105-
setLintWarning: PropTypes.func.isRequired,
106-
setTheme: PropTypes.func.isRequired,
107-
setFontSize: PropTypes.func.isRequired,
108-
setLineNumbers: PropTypes.func.isRequired,
109-
setAutosave: PropTypes.func.isRequired,
110-
setTextOutput: PropTypes.func.isRequired,
111-
setGridOutput: PropTypes.func.isRequired,
112-
setSoundOutput: PropTypes.func.isRequired,
113-
};
114-
11592
export default withRouter(MobilePreferences);

client/modules/Mobile/MobileSketchView.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Header from '../../components/mobile/Header';
77
import IconButton from '../../components/mobile/IconButton';
88
import PreviewFrame from '../IDE/components/PreviewFrame';
99
import Screen from '../../components/mobile/MobileScreen';
10+
import Console from '../IDE/components/Console';
1011
import * as ProjectActions from '../IDE/actions/project';
1112
import * as IDEActions from '../IDE/actions/ide';
1213
import * as PreferencesActions from '../IDE/actions/preferences';
@@ -17,6 +18,7 @@ import { getHTMLFile } from '../IDE/reducers/files';
1718

1819
import { ExitIcon } from '../../common/icons';
1920
import { remSize } from '../../theme';
21+
import Footer from '../../components/mobile/Footer';
2022

2123
const Content = styled.div`
2224
z-index: 0;
@@ -73,6 +75,7 @@ const MobileSketchView = (props) => {
7375
clearConsole={clearConsole}
7476
/>
7577
</Content>
78+
<Footer before={<Console />} />
7679
</Screen>);
7780
};
7881

package-lock.json

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)