Skip to content

Commit 617f006

Browse files
shinytang6catarak
authored andcommitted
Improve current console (#656)
* init v2 * make replay work * fix a failing scenary of react-frame * fix some bugs * delete/comment some files * remove * fix some bugs && remove more comments * remove unnecessary lines * minor tweak * fix some bugs * try to hook iframe using webpack * update * changes according to cassie * minor tweak * fix lint * extract sass * add icons * update webpack config * update webpack configuration * update * tweak * fix a small bug
1 parent 903713e commit 617f006

23 files changed

+348
-132
lines changed

client/images/console-debug-dark.svg

Lines changed: 1 addition & 0 deletions
Loading

client/images/console-debug-light.svg

Lines changed: 1 addition & 0 deletions
Loading

client/images/console-error-dark.svg

Lines changed: 1 addition & 0 deletions
Loading

client/images/console-error-light.svg

Lines changed: 1 addition & 0 deletions
Loading

client/images/console-info-dark.svg

Lines changed: 1 addition & 0 deletions
Loading

client/images/console-info-light.svg

Lines changed: 1 addition & 0 deletions
Loading

client/images/console-warn-dark.svg

Lines changed: 1 addition & 0 deletions
Loading

client/images/console-warn-light.svg

Lines changed: 1 addition & 0 deletions
Loading

client/modules/IDE/components/Console.jsx

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,63 @@ import PropTypes from 'prop-types';
22
import React from 'react';
33
import InlineSVG from 'react-inlinesvg';
44
import classNames from 'classnames';
5+
import { Console as ConsoleFeed } from 'console-feed';
6+
import { CONSOLE_FEED_WITHOUT_ICONS, CONSOLE_FEED_LIGHT_STYLES, CONSOLE_FEED_DARK_STYLES, CONSOLE_FEED_CONTRAST_STYLES } from '../../../styles/components/_console-feed.scss';
7+
import warnLightUrl from '../../../images/console-warn-light.svg';
8+
import warnDarkUrl from '../../../images/console-warn-dark.svg';
9+
import errorLightUrl from '../../../images/console-error-light.svg';
10+
import errorDarkUrl from '../../../images/console-error-dark.svg';
11+
import debugLightUrl from '../../../images/console-debug-light.svg';
12+
import debugDarkUrl from '../../../images/console-debug-dark.svg';
13+
import infoLightUrl from '../../../images/console-info-light.svg';
14+
import infoDarkUrl from '../../../images/console-info-dark.svg';
515

616
const upArrowUrl = require('../../../images/up-arrow.svg');
717
const downArrowUrl = require('../../../images/down-arrow.svg');
818

919
class Console extends React.Component {
10-
componentDidUpdate() {
20+
componentDidUpdate(prevProps) {
1121
this.consoleMessages.scrollTop = this.consoleMessages.scrollHeight;
22+
if (this.props.theme !== prevProps.theme) {
23+
this.props.clearConsole();
24+
this.props.dispatchConsoleEvent(this.props.consoleEvents);
25+
}
26+
}
27+
28+
getConsoleFeedStyle(theme, times) {
29+
const style = {};
30+
const CONSOLE_FEED_LIGHT_ICONS = {
31+
LOG_WARN_ICON: `url(${warnLightUrl})`,
32+
LOG_ERROR_ICON: `url(${errorLightUrl})`,
33+
LOG_DEBUG_ICON: `url(${debugLightUrl})`,
34+
LOG_INFO_ICON: `url(${infoLightUrl})`
35+
};
36+
const CONSOLE_FEED_DARK_ICONS = {
37+
LOG_WARN_ICON: `url(${warnDarkUrl})`,
38+
LOG_ERROR_ICON: `url(${errorDarkUrl})`,
39+
LOG_DEBUG_ICON: `url(${debugDarkUrl})`,
40+
LOG_INFO_ICON: `url(${infoDarkUrl})`
41+
};
42+
if (times > 1) {
43+
Object.assign(style, CONSOLE_FEED_WITHOUT_ICONS);
44+
}
45+
switch (theme) {
46+
case 'light':
47+
return Object.assign(CONSOLE_FEED_LIGHT_STYLES, CONSOLE_FEED_LIGHT_ICONS, style);
48+
case 'dark':
49+
return Object.assign(CONSOLE_FEED_DARK_STYLES, CONSOLE_FEED_DARK_ICONS, style);
50+
case 'contrast':
51+
return Object.assign(CONSOLE_FEED_CONTRAST_STYLES, CONSOLE_FEED_DARK_ICONS, style);
52+
default:
53+
return '';
54+
}
55+
}
56+
57+
formatData(args) {
58+
if (!Array.isArray(args)) {
59+
return Array.of(args);
60+
}
61+
return args;
1262
}
1363

1464
render() {
@@ -39,17 +89,25 @@ class Console extends React.Component {
3989
</div>
4090
<div ref={(element) => { this.consoleMessages = element; }} className="preview-console__messages">
4191
{this.props.consoleEvents.map((consoleEvent) => {
42-
const { arguments: args, method } = consoleEvent;
92+
const { arguments: args, method, times } = consoleEvent;
93+
const { theme } = this.props;
94+
Object.assign(consoleEvent, { data: this.formatData(args) });
4395
if (Object.keys(args).length === 0) {
4496
return (
45-
<div key={consoleEvent.id} className="preview-console__undefined">
97+
<div key={consoleEvent.id} className="preview-console__message preview-console__message--undefined">
4698
<span key={`${consoleEvent.id}-0`}>undefined</span>
4799
</div>
48100
);
49101
}
50102
return (
51-
<div key={consoleEvent.id} className={`preview-console__${method}`}>
52-
{Object.keys(args).map(key => <span key={`${consoleEvent.id}-${key}`}>{args[key]}</span>)}
103+
<div key={consoleEvent.id} className={`preview-console__message preview-console__message--${method}`}>
104+
{ times > 1 &&
105+
<div className="preview-console__logged-times">{times}</div>
106+
}
107+
<ConsoleFeed
108+
styles={this.getConsoleFeedStyle(theme, times)}
109+
logs={Array.of(consoleEvent)}
110+
/>
53111
</div>
54112
);
55113
})}
@@ -67,7 +125,9 @@ Console.propTypes = {
67125
isExpanded: PropTypes.bool.isRequired,
68126
collapseConsole: PropTypes.func.isRequired,
69127
expandConsole: PropTypes.func.isRequired,
70-
clearConsole: PropTypes.func.isRequired
128+
clearConsole: PropTypes.func.isRequired,
129+
dispatchConsoleEvent: PropTypes.func.isRequired,
130+
theme: PropTypes.string.isRequired
71131
};
72132

73133
Console.defaultProps = {

client/modules/IDE/components/Editor.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ class Editor extends React.Component {
116116
this.props.setUnsavedChanges(true);
117117
this.props.updateFileContent(this.props.file.name, this._cm.getValue());
118118
if (this.props.autorefresh && this.props.isPlaying) {
119-
this.props.startRefreshSketch();
120119
this.props.clearConsole();
120+
this.props.startRefreshSketch();
121121
}
122122
}, 400));
123123

0 commit comments

Comments
 (0)