Add code reload component

This commit is contained in:
Andre Medeiros 2018-10-03 14:18:43 -04:00 committed by Pascal Precht
parent 3b45128f20
commit 3339d27ee7
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
2 changed files with 58 additions and 9 deletions

View File

@ -4,21 +4,25 @@ import {
Grid
} from "tabler-react";
import ApplicationPreviewContainer from '../containers/ApplicationPreviewContainer';
import TextEditorContainer from '../containers/TextEditorContainer';
import FileExplorerContainer from '../containers/FileExplorerContainer';
class FiddleLayout extends React.Component {
render() {
return (
<Grid.Row className="my-5">
<Grid.Col md={3}>
<Page.Title>Fiddle</Page.Title>
<FileExplorerContainer />
</Grid.Col>
<Grid.Col md={9}>
<TextEditorContainer />
</Grid.Col>
</Grid.Row>
<Page.Content title="Fiddle">
<Grid.Row className="my-5">
<Grid.Col md={3}>
<Page.Title>Fiddle</Page.Title>
<FileExplorerContainer />
</Grid.Col>
<Grid.Col md={9}>
<TextEditorContainer />
</Grid.Col>
</Grid.Row>
<ApplicationPreviewContainer />
</Page.Content>
);
}
}

View File

@ -0,0 +1,45 @@
import PropTypes from 'prop-types';
import React from 'react';
class ApplicationPreviewContainer extends React.Component {
constructor(props) {
super(props);
this.state = {
previewUrl: props.previewUrl || 'http://localhost:8000'
};
}
render() {
return (
<div>
<div className="input-group mb-3">
<input type="text" className="form-control" placeholder="URL" ref={(input) => this.locationInput = input} value={this.props.previewUrl} />
<div className="input-group-append">
<button className="btn btn-outline-secondary" type="button" onClick={(e) => this.handlePreviewGo(e)}>Go</button>
</div>
</div>
<iframe width="100%" height="500" title="Preview" ref={(iframe) => this.previewIframe = iframe} onLoad={(e) => this.handlePreviewChange(e)} src="http://localhost:8000"></iframe>
</div>
);
}
handlePreviewChange(ev) {
try {
let url = ev.target.contentWindow.location.toString();
this.setState({previewUrl: url});
} catch(e) {
// Nothing here.
}
}
handlePreviewGo() {
this.previewIframe.src = this.locationInput.value;
}
}
ApplicationPreviewContainer.propTypes = {
previewUrl: PropTypes.string
};
export default ApplicationPreviewContainer;