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
|
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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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