From 74cfa9e3272688dde4ae9c31c07d82a003621b45 Mon Sep 17 00:00:00 2001 From: Kushagra Gour Date: Sat, 29 Sep 2018 13:15:03 +0530 Subject: [PATCH] Move Console to separate component. --- src/components/Console.jsx | 70 +++++++++++++++++++++++++++++ src/components/ContentWrap.jsx | 80 +++++++++------------------------- 2 files changed, 90 insertions(+), 60 deletions(-) create mode 100644 src/components/Console.jsx diff --git a/src/components/Console.jsx b/src/components/Console.jsx new file mode 100644 index 0000000..eda09bd --- /dev/null +++ b/src/components/Console.jsx @@ -0,0 +1,70 @@ +import { h } from 'preact'; +import CodeMirrorBox from './CodeMirrorBox'; + +export function Console({ + isConsoleOpen, + onConsoleHeaderDblClick, + onClearConsoleBtnClick, + toggleConsole, + onEvalInputKeyup, + onReady +}) { + return ( +
+ +
+ + + + +
+
+ ); +} diff --git a/src/components/ContentWrap.jsx b/src/components/ContentWrap.jsx index 363a456..d7fb727 100644 --- a/src/components/ContentWrap.jsx +++ b/src/components/ContentWrap.jsx @@ -6,7 +6,7 @@ import { log, writeFile, loadJS, getCompleteHtml } from '../utils'; import { SplitPane } from './SplitPane.jsx'; import { trackEvent } from '../analytics'; import CodeMirror from '../CodeMirror'; -import CodeMirrorBox from './CodeMirrorBox'; +import { Console } from './Console'; import { deferred } from '../deferred'; import CssSettingsModal from './CssSettingsModal'; const minCodeWrapSize = 33; @@ -52,7 +52,7 @@ export default class ContentWrap extends Component { } componentDidUpdate() { // HACK: becuase its a DOM manipulation - window.logCountEl.textContent = this.logCount; + this.updateLogCount(); // log('🚀', 'didupdate', this.props.currentItem); // if (this.isValidItem(this.props.currentItem)) { @@ -583,6 +583,12 @@ export default class ContentWrap extends Component { }, 500); } + updateLogCount() { + if (window.logCountEl) { + logCountEl.textContent = this.logCount; + } + } + onMessageFromConsole() { /* eslint-disable no-param-reassign */ [...arguments].forEach(arg => { @@ -614,7 +620,7 @@ export default class ContentWrap extends Component { this.consoleCm.scrollTo(0, Infinity); this.logCount++; }); - logCountEl.textContent = this.logCount; + this.updateLogCount(); /* eslint-enable no-param-reassign */ } @@ -638,7 +644,7 @@ export default class ContentWrap extends Component { clearConsole() { this.consoleCm.setValue(''); this.logCount = 0; - window.logCountEl.textContent = this.logCount; + this.updateLogCount(); } clearConsoleBtnClickHandler() { this.clearConsole(); @@ -884,62 +890,16 @@ export default class ContentWrap extends Component { id="demo-frame" allowfullscreen /> -
- -
- - - - -
-
+ (this.consoleCm = el)} + />