feat(ui): keep state in frame

This commit is contained in:
Anthony Laibe 2019-02-12 10:10:34 +00:00 committed by Iuri Matias
parent bc24598175
commit cd326303ae
6 changed files with 68 additions and 35 deletions

View File

@ -530,3 +530,11 @@ export function updateDeploymentPipeline(value) {
payload: value payload: value
}; };
} }
export const UPDATE_PREVIEW_URL = 'UPDATE_PREVIEW_URL';
export function updatePreviewUrl(value) {
return {
type: UPDATE_PREVIEW_URL,
payload: value
};
}

View File

@ -1,4 +1,5 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types';
import {Button, InputGroup, Input, InputGroupAddon} from 'reactstrap'; import {Button, InputGroup, Input, InputGroupAddon} from 'reactstrap';
import FontAwesome from 'react-fontawesome'; import FontAwesome from 'react-fontawesome';
@ -7,23 +8,18 @@ class Preview extends React.Component {
super(props); super(props);
this.state = { this.state = {
previewUrl: `${window.location.protocol}//${window.location.host}/` previewUrl: props.previewUrl
}; };
} }
handlePreviewUrlChange(ev) { handlePreviewUrlChange(ev) {
this.setState({previewUrl: ev.target.value}); this.setState({previewUrl: ev.target.value});
} this.props.updatePreviewUrl(ev.target.value);
handlePreviewChange(ev) {
try {
let url = ev.target.contentWindow.location.toString();
this.setState({previewUrl: url});
} catch(e) {}
} }
handlePreviewGo() { handlePreviewGo() {
this.previewIframe.src = this.state.previewUrl; this.previewIframe.src = this.state.previewUrl;
this.props.updatePreviewUrl(this.state.previewUrl);
} }
render() { render() {
@ -43,12 +39,17 @@ class Preview extends React.Component {
height="100%" height="100%"
title="Preview" title="Preview"
ref={(iframe) => this.previewIframe = iframe} ref={(iframe) => this.previewIframe = iframe}
onLoad={(e) => this.handlePreviewChange(e)} src={this.state.previewUrl}> src={this.state.previewUrl}>
</iframe> </iframe>
</div> </div>
); );
} }
} }
Preview.propTypes = {
previewUrl: PropTypes.string,
updatePreviewUrl: PropTypes.func,
};
export default Preview; export default Preview;

View File

@ -222,7 +222,7 @@ class EditorContainer extends React.Component {
{this.renderTextEditor()} {this.renderTextEditor()}
{this.state.currentAsideTab.label && this.renderAside()} {this.renderAside()}
</Row> </Row>
</React.Fragment> </React.Fragment>
); );

View File

@ -2,14 +2,18 @@ import React, {Component} from 'react';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import {Card, CardBody} from 'reactstrap'; import {Card, CardBody} from 'reactstrap';
import classNames from 'classnames';
import Preview from '../components/Preview'; import Preview from '../components/Preview';
import {getContractsByPath} from "../reducers/selectors"; import {getContractsByPath, getPreviewUrl} from "../reducers/selectors";
import ContractDetail from '../components/ContractDetail'; import ContractDetail from '../components/ContractDetail';
import ContractTransactionsContainer from './ContractTransactionsContainer'; import ContractTransactionsContainer from './ContractTransactionsContainer';
import ContractOverviewContainer from '../containers/ContractOverviewContainer'; import ContractOverviewContainer from '../containers/ContractOverviewContainer';
import ContractDebuggerContainer from '../containers/ContractDebuggerContainer'; import ContractDebuggerContainer from '../containers/ContractDebuggerContainer';
import { TextEditorToolbarTabs } from '../components/TextEditorToolbar'; import { TextEditorToolbarTabs } from '../components/TextEditorToolbar';
import {
updatePreviewUrl as updatePreviewUrlAction
} from '../actions';
class TextEditorAsideContainer extends Component { class TextEditorAsideContainer extends Component {
renderContent(contract, index) { renderContent(contract, index) {
@ -41,30 +45,33 @@ class TextEditorAsideContainer extends Component {
} }
render() { render() {
if (this.props.currentAsideTab.label === TextEditorToolbarTabs.Browser.label) { return (
return <Preview/>; <React.Fragment>
} <div className={classNames('h-100', {'d-none': this.props.currentAsideTab.label !== TextEditorToolbarTabs.Browser.label})}>
if (this.props.currentAsideTab.label === TextEditorToolbarTabs.Debugger.label) { <Preview previewUrl={this.props.previewUrl} updatePreviewUrl={this.props.updatePreviewUrl}/>
return ( </div>
<React.Fragment> {this.props.currentAsideTab.label === TextEditorToolbarTabs.Debugger.label &&
<h2>Debugger</h2> <React.Fragment>
<ContractDebuggerContainer debuggerTransactionHash={this.props.debuggerTransactionHash}/> <h2>Debugger</h2>
</React.Fragment> <ContractDebuggerContainer debuggerTransactionHash={this.props.debuggerTransactionHash}/>
); </React.Fragment>
} }
return this.props.contracts.map((contract, index) => ( {this.props.contracts.map((contract, index) => (
<Card key={'contract-' + index} className="editor-aside-card rounded-0 border-top-0"> <Card key={'contract-' + index} className="editor-aside-card rounded-0 border-top-0">
<CardBody> <CardBody>
{this.renderContent(contract, index)} {this.renderContent(contract, index)}
</CardBody> </CardBody>
</Card> </Card>
)); ))}
</React.Fragment>
);
} }
} }
function mapStateToProps(state, props) { function mapStateToProps(state, props) {
return { return {
contracts: getContractsByPath(state, props.currentFile.path) contracts: getContractsByPath(state, props.currentFile.path),
previewUrl: getPreviewUrl(state)
}; };
} }
@ -72,10 +79,14 @@ TextEditorAsideContainer.propTypes = {
currentFile: PropTypes.object, currentFile: PropTypes.object,
debuggerTransactionHash: PropTypes.string, debuggerTransactionHash: PropTypes.string,
currentAsideTab: PropTypes.object, currentAsideTab: PropTypes.object,
contracts: PropTypes.array contracts: PropTypes.array,
updatePreviewUrl: PropTypes.func,
previewUrl: PropTypes.string
}; };
export default connect( export default connect(
mapStateToProps, mapStateToProps,
{} {
updatePreviewUrl: updatePreviewUrlAction
}
)(TextEditorAsideContainer); )(TextEditorAsideContainer);

View File

@ -1,7 +1,7 @@
import {combineReducers} from 'redux'; import {combineReducers} from 'redux';
import {REQUEST, SUCCESS, FAILURE, CONTRACT_COMPILE, FILES, LOGOUT, AUTHENTICATE, import {REQUEST, SUCCESS, FAILURE, CONTRACT_COMPILE, FILES, LOGOUT, AUTHENTICATE,
FETCH_CREDENTIALS, UPDATE_BASE_ETHER, CHANGE_THEME, FETCH_THEME, EXPLORER_SEARCH, DEBUGGER_INFO, FETCH_CREDENTIALS, UPDATE_BASE_ETHER, CHANGE_THEME, FETCH_THEME, EXPLORER_SEARCH, DEBUGGER_INFO,
SIGN_MESSAGE, VERIFY_MESSAGE, TOGGLE_BREAKPOINT, SIGN_MESSAGE, VERIFY_MESSAGE, TOGGLE_BREAKPOINT, UPDATE_PREVIEW_URL,
UPDATE_DEPLOYMENT_PIPELINE, WEB3_CONNECT, WEB3_DEPLOY, WEB3_ESTIMAGE_GAS, FETCH_EDITOR_TABS} from "../actions"; UPDATE_DEPLOYMENT_PIPELINE, WEB3_CONNECT, WEB3_DEPLOY, WEB3_ESTIMAGE_GAS, FETCH_EDITOR_TABS} from "../actions";
import {EMBARK_PROCESS_NAME, DARK_THEME, DEPLOYMENT_PIPELINES, DEFAULT_HOST, ELEMENTS_LIMIT} from '../constants'; import {EMBARK_PROCESS_NAME, DARK_THEME, DEPLOYMENT_PIPELINES, DEFAULT_HOST, ELEMENTS_LIMIT} from '../constants';
@ -369,6 +369,13 @@ function editorTabs(state = [], action) {
return state; return state;
} }
function previewUrl(state= `${window.location.protocol}//${window.location.host}/`, action) {
if (action.type === UPDATE_PREVIEW_URL) {
return action.payload;
}
return state;
}
const rootReducer = combineReducers({ const rootReducer = combineReducers({
entities, entities,
loading, loading,
@ -385,7 +392,8 @@ const rootReducer = combineReducers({
web3, web3,
debuggerInfo, debuggerInfo,
theme, theme,
editorTabs editorTabs,
previewUrl
}); });
export default rootReducer; export default rootReducer;

View File

@ -239,5 +239,10 @@ export function getDebuggerLine(state) {
} }
export function getEditorTabs(state) { export function getEditorTabs(state) {
return state.editorTabs return state.editorTabs;
} }
export function getPreviewUrl(state) {
return state.previewUrl;
}