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 Grid
} from "tabler-react"; } from "tabler-react";
import ApplicationPreviewContainer from '../containers/ApplicationPreviewContainer';
import TextEditorContainer from '../containers/TextEditorContainer'; import TextEditorContainer from '../containers/TextEditorContainer';
import FileExplorerContainer from '../containers/FileExplorerContainer'; import FileExplorerContainer from '../containers/FileExplorerContainer';
class FiddleLayout extends React.Component { class FiddleLayout extends React.Component {
render() { render() {
return ( return (
<Grid.Row className="my-5"> <Page.Content title="Fiddle">
<Grid.Col md={3}> <Grid.Row className="my-5">
<Page.Title>Fiddle</Page.Title> <Grid.Col md={3}>
<FileExplorerContainer /> <Page.Title>Fiddle</Page.Title>
</Grid.Col> <FileExplorerContainer />
<Grid.Col md={9}> </Grid.Col>
<TextEditorContainer /> <Grid.Col md={9}>
</Grid.Col> <TextEditorContainer />
</Grid.Row> </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;