Grant permission to load app widget.

This commit is contained in:
Richard Lewis 2017-07-26 16:47:58 +01:00
parent 76f4f88fcd
commit 9f52c13bea
2 changed files with 21 additions and 9 deletions

View file

@ -1,30 +1,41 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { URL, URLSearchParams } from 'url'; import url from 'url';
export default class AppPermission extends React.Component { export default class AppPermission extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
const curl = this.getCurl();
this.state = { this.state = {
curl: this.getCurl(), curl: curl,
}; };
console.log('curl', curl);
} }
getCurl() { getCurl() {
let wurl = URL.parse(this.props.url); const wurl = url.parse(this.props.url);
console.log('wurl', wurl); let curl;
if(wurl.searchParams.get('url')) {
let curl = wurl.searchParams.get('url'); const searchParams = new URLSearchParams(wurl.search);
console.log('curl', curl); if(searchParams && searchParams.get('url')) {
curl = searchParams.get('url');
} }
curl = curl || wurl;
return curl;
} }
render() { render() {
return ( return (
<div> <div className='mx_AppPermissionWarning'>
Load widget with URL : {this.state.cUrl} <div className='mx_AppPermissionWarningImage'>
<img src='img/warning.svg' alt='Warning'/>
</div>
<div className='mx_AppPermissionWarningText'>
<span className='mx_AppPermissionWarningTextLabel'>Do you want to load widget from URL?:</span> <span className='mx_AppPermissionWarningTextURL'>{this.state.curl}</span>
</div>
<input <input
className='mx_AppPermissionButton'
type='button' type='button'
value='Allow' value='Allow'
onClick={this.props.onPermissionGranted} onClick={this.props.onPermissionGranted}

View file

@ -174,6 +174,7 @@ export default React.createClass({
appTileBody = ( appTileBody = (
<AppPermission <AppPermission
url={this.state.widgetUrl} url={this.state.widgetUrl}
onPermissionGranted={this._grantWidgetPermission}
/> />
); );
} }