mirror of https://github.com/embarklabs/embark.git
Add code reload component
This commit is contained in:
parent
3b45128f20
commit
3339d27ee7
|
@ -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>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
Loading…
Reference in New Issue