2017-01-25 18:51:41 +01:00
|
|
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
2016-12-27 11:15:02 +01:00
|
|
|
// This file is part of Parity.
|
|
|
|
|
|
|
|
// Parity is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// Parity is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-02-04 09:52:14 +01:00
|
|
|
import { observer } from 'mobx-react';
|
2016-12-27 11:15:02 +01:00
|
|
|
import React, { Component, PropTypes } from 'react';
|
2017-02-04 09:52:14 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2016-12-27 11:15:02 +01:00
|
|
|
|
|
|
|
import AddressBar from './AddressBar';
|
2017-02-04 09:52:14 +01:00
|
|
|
import Store from './store';
|
2016-12-27 11:15:02 +01:00
|
|
|
|
|
|
|
import styles from './web.css';
|
|
|
|
|
2017-02-04 09:52:14 +01:00
|
|
|
@observer
|
2016-12-27 11:15:02 +01:00
|
|
|
export default class Web extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
api: PropTypes.object.isRequired
|
|
|
|
}
|
|
|
|
|
2017-01-05 21:15:01 +01:00
|
|
|
static propTypes = {
|
|
|
|
params: PropTypes.object.isRequired
|
|
|
|
}
|
|
|
|
|
2017-02-04 09:52:14 +01:00
|
|
|
store = Store.get(this.context.api);
|
2016-12-27 11:15:02 +01:00
|
|
|
|
|
|
|
componentDidMount () {
|
2017-02-04 09:52:14 +01:00
|
|
|
this.store.gotoUrl(this.props.params.url);
|
2016-12-27 11:15:02 +01:00
|
|
|
}
|
|
|
|
|
2017-01-05 21:15:01 +01:00
|
|
|
componentWillReceiveProps (props) {
|
2017-02-04 09:52:14 +01:00
|
|
|
this.store.gotoUrl(props.params.url);
|
2016-12-27 11:15:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2017-02-04 09:52:14 +01:00
|
|
|
const { currentUrl, token } = this.store;
|
2016-12-27 11:15:02 +01:00
|
|
|
|
|
|
|
if (!token) {
|
|
|
|
return (
|
|
|
|
<div className={ styles.wrapper }>
|
|
|
|
<h1 className={ styles.loading }>
|
2017-02-04 09:52:14 +01:00
|
|
|
<FormattedMessage
|
|
|
|
id='web.requestToken'
|
|
|
|
defaultMessage='Requesting access token...'
|
|
|
|
/>
|
2016-12-27 11:15:02 +01:00
|
|
|
</h1>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-02-04 09:52:14 +01:00
|
|
|
return currentUrl
|
|
|
|
? this.renderFrame()
|
|
|
|
: null;
|
|
|
|
}
|
2017-01-05 21:15:01 +01:00
|
|
|
|
2017-02-04 09:52:14 +01:00
|
|
|
renderFrame () {
|
|
|
|
const { encodedPath, frameId } = this.store;
|
2017-01-05 21:15:01 +01:00
|
|
|
|
2016-12-27 11:15:02 +01:00
|
|
|
return (
|
|
|
|
<div className={ styles.wrapper }>
|
|
|
|
<AddressBar
|
|
|
|
className={ styles.url }
|
2017-02-04 09:52:14 +01:00
|
|
|
store={ this.store }
|
2016-12-27 11:15:02 +01:00
|
|
|
/>
|
|
|
|
<iframe
|
|
|
|
className={ styles.frame }
|
|
|
|
frameBorder={ 0 }
|
2017-02-04 09:52:14 +01:00
|
|
|
id={ frameId }
|
|
|
|
name={ frameId }
|
2017-01-05 21:15:01 +01:00
|
|
|
onLoad={ this.iframeOnLoad }
|
2016-12-27 11:15:02 +01:00
|
|
|
sandbox='allow-forms allow-same-origin allow-scripts'
|
|
|
|
scrolling='auto'
|
2017-02-04 09:52:14 +01:00
|
|
|
src={ encodedPath }
|
2017-01-18 13:05:01 +01:00
|
|
|
/>
|
2016-12-27 11:15:02 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-05 21:15:01 +01:00
|
|
|
iframeOnLoad = () => {
|
2017-02-04 09:52:14 +01:00
|
|
|
this.store.setLoading(false);
|
2016-12-27 11:15:02 +01:00
|
|
|
};
|
|
|
|
}
|