This commit is contained in:
Cassie Tarakajian 2019-03-05 16:25:34 -05:00 committed by GitHub
parent d17364a2ce
commit d9670f7bc3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 34 deletions

View file

@ -37,10 +37,13 @@ import Feedback from '../components/Feedback';
class IDEView extends React.Component { class IDEView extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this._handleConsolePaneOnDragFinished = this._handleConsolePaneOnDragFinished.bind(this);
this._handleSidebarPaneOnDragFinished = this._handleSidebarPaneOnDragFinished.bind(this);
this.handleGlobalKeydown = this.handleGlobalKeydown.bind(this); this.handleGlobalKeydown = this.handleGlobalKeydown.bind(this);
this.warnIfUnsavedChanges = this.warnIfUnsavedChanges.bind(this); this.warnIfUnsavedChanges = this.warnIfUnsavedChanges.bind(this);
this.state = {
consoleSize: props.ide.consoleIsExpanded ? 150 : 29,
sidebarSize: props.ide.sidebarIsExpanded ? 160 : 20
};
} }
componentDidMount() { componentDidMount() {
@ -56,10 +59,6 @@ class IDEView extends React.Component {
} }
} }
this.consoleSize = this.props.ide.consoleIsExpanded ? 150 : 29;
this.sidebarSize = this.props.ide.sidebarIsExpanded ? 160 : 20;
this.forceUpdate();
this.isMac = navigator.userAgent.toLowerCase().indexOf('mac') !== -1; this.isMac = navigator.userAgent.toLowerCase().indexOf('mac') !== -1;
document.addEventListener('keydown', this.handleGlobalKeydown, false); document.addEventListener('keydown', this.handleGlobalKeydown, false);
@ -75,17 +74,17 @@ class IDEView extends React.Component {
if (nextProps.location !== this.props.location) { if (nextProps.location !== this.props.location) {
this.props.setPreviousPath(this.props.location.pathname); this.props.setPreviousPath(this.props.location.pathname);
} }
}
componentWillUpdate(nextProps) {
if (this.props.ide.consoleIsExpanded !== nextProps.ide.consoleIsExpanded) { if (this.props.ide.consoleIsExpanded !== nextProps.ide.consoleIsExpanded) {
this.consoleSize = nextProps.ide.consoleIsExpanded ? 150 : 29; this.setState({ consoleSize: nextProps.ide.consoleIsExpanded ? 150 : 29 });
} }
if (this.props.ide.sidebarIsExpanded !== nextProps.ide.sidebarIsExpanded) { if (this.props.ide.sidebarIsExpanded !== nextProps.ide.sidebarIsExpanded) {
this.sidebarSize = nextProps.ide.sidebarIsExpanded ? 160 : 20; this.setState({ sidebarSize: nextProps.ide.sidebarIsExpanded ? 160 : 20 });
} }
}
componentWillUpdate(nextProps) {
if (nextProps.params.project_id && !this.props.params.project_id) { if (nextProps.params.project_id && !this.props.params.project_id) {
if (nextProps.params.project_id !== nextProps.project.id) { if (nextProps.params.project_id !== nextProps.project.id) {
this.props.getProject(nextProps.params.project_id); this.props.getProject(nextProps.params.project_id);
@ -127,30 +126,12 @@ class IDEView extends React.Component {
document.removeEventListener('keydown', this.handleGlobalKeydown, false); document.removeEventListener('keydown', this.handleGlobalKeydown, false);
clearTimeout(this.autosaveInterval); clearTimeout(this.autosaveInterval);
this.autosaveInterval = null; this.autosaveInterval = null;
this.consoleSize = undefined;
this.sidebarSize = undefined;
} }
isUserOwner() { isUserOwner() {
return this.props.project.owner && this.props.project.owner.id === this.props.user.id; return this.props.project.owner && this.props.project.owner.id === this.props.user.id;
} }
_handleConsolePaneOnDragFinished() {
this.consoleSize = this.consolePane.state.draggedSize;
this.consolePane.setState({
resized: false,
draggedSize: undefined,
});
}
_handleSidebarPaneOnDragFinished() {
this.sidebarSize = this.sidebarPane.state.draggedSize;
this.sidebarPane.setState({
resized: false,
draggedSize: undefined
});
}
handleGlobalKeydown(e) { handleGlobalKeydown(e) {
// 83 === s // 83 === s
if (e.keyCode === 83 && ((e.metaKey && this.isMac) || (e.ctrlKey && !this.isMac))) { if (e.keyCode === 83 && ((e.metaKey && this.isMac) || (e.ctrlKey && !this.isMac))) {
@ -245,8 +226,8 @@ class IDEView extends React.Component {
<div className="editor-preview-container"> <div className="editor-preview-container">
<SplitPane <SplitPane
split="vertical" split="vertical"
defaultSize={this.sidebarSize} size={this.state.sidebarSize}
ref={(element) => { this.sidebarPane = element; }} onChange={size => this.setState({ sidebarSize: size })}
onDragFinished={this._handleSidebarPaneOnDragFinished} onDragFinished={this._handleSidebarPaneOnDragFinished}
allowResize={this.props.ide.sidebarIsExpanded} allowResize={this.props.ide.sidebarIsExpanded}
minSize={20} minSize={20}
@ -275,10 +256,9 @@ class IDEView extends React.Component {
<SplitPane <SplitPane
split="horizontal" split="horizontal"
primary="second" primary="second"
defaultSize={this.consoleSize} size={this.state.consoleSize}
minSize={29} minSize={29}
ref={(element) => { this.consolePane = element; }} onChange={size => this.setState({ consoleSize: size })}
onDragFinished={this._handleConsolePaneOnDragFinished}
allowResize={this.props.ide.consoleIsExpanded} allowResize={this.props.ide.consoleIsExpanded}
className="editor-preview-subpanel" className="editor-preview-subpanel"
> >

View file

@ -134,7 +134,7 @@
"react-inlinesvg": "^0.7.5", "react-inlinesvg": "^0.7.5",
"react-redux": "^5.1.1", "react-redux": "^5.1.1",
"react-router": "^3.2.1", "react-router": "^3.2.1",
"react-split-pane": "^0.1.76", "react-split-pane": "^0.1.85",
"react-tabs": "^2.3.0", "react-tabs": "^2.3.0",
"redux": "^3.7.2", "redux": "^3.7.2",
"redux-devtools": "^3.4.2", "redux-devtools": "^3.4.2",