Files
ThreadNet-Web/src/components/views/elements/AppPermission.js
T

77 lines
2.6 KiB
JavaScript
Raw Normal View History

2017-07-26 11:28:43 +01:00
import React from 'react';
import PropTypes from 'prop-types';
2017-07-26 16:47:58 +01:00
import url from 'url';
2017-07-28 16:39:18 +01:00
import { _t } from '../../../languageHandler';
2018-06-26 11:59:16 +01:00
import WidgetUtils from "../../../utils/WidgetUtils";
2017-07-26 11:28:43 +01:00
export default class AppPermission extends React.Component {
constructor(props) {
super(props);
2017-07-28 10:18:06 +01:00
const curlBase = this.getCurlBase();
2017-07-28 16:36:06 +01:00
this.state = { curlBase: curlBase};
2017-07-26 11:28:43 +01:00
}
2017-07-28 10:18:06 +01:00
// Return string representation of content URL without query parameters
getCurlBase() {
2017-07-26 16:47:58 +01:00
const wurl = url.parse(this.props.url);
let curl;
2017-07-28 10:01:58 +01:00
let curlString;
2017-07-26 16:47:58 +01:00
const searchParams = new URLSearchParams(wurl.search);
2017-07-28 10:01:58 +01:00
2018-05-27 11:12:55 -06:00
if (WidgetUtils.isScalarUrl(wurl) && searchParams && searchParams.get('url')) {
2017-07-28 10:01:58 +01:00
curl = url.parse(searchParams.get('url'));
2017-11-16 13:19:36 +00:00
if (curl) {
2017-07-28 10:01:58 +01:00
curl.search = curl.query = "";
curlString = curl.format();
}
2017-07-26 11:28:43 +01:00
}
if (!curl && wurl) {
wurl.search = wurl.query = "";
2017-07-28 10:01:58 +01:00
curlString = wurl.format();
}
2017-07-28 10:01:58 +01:00
return curlString;
2017-07-26 11:28:43 +01:00
}
render() {
let e2eWarningText;
if (this.props.isRoomEncrypted) {
e2eWarningText =
<span className='mx_AppPermissionWarningTextLabel'>{ _t('NOTE: Apps are not end-to-end encrypted') }</span>;
}
const cookieWarning =
<span className='mx_AppPermissionWarningTextLabel'>
{ _t('Warning: This widget might use cookies.') }
</span>;
2017-07-26 11:28:43 +01:00
return (
2017-07-26 16:47:58 +01:00
<div className='mx_AppPermissionWarning'>
<div className='mx_AppPermissionWarningImage'>
2019-02-01 23:24:56 +01:00
<img src={require("../../../../res/img/feather-icons/warning-triangle.svg")} alt={_t('Warning!')} />
2017-07-26 16:47:58 +01:00
</div>
<div className='mx_AppPermissionWarningText'>
<span className='mx_AppPermissionWarningTextLabel'>{ _t('Do you want to load widget from URL:') }</span> <span className='mx_AppPermissionWarningTextURL'>{ this.state.curlBase }</span>
{ e2eWarningText }
{ cookieWarning }
2017-07-26 16:47:58 +01:00
</div>
2017-07-26 11:28:43 +01:00
<input
2017-07-26 16:47:58 +01:00
className='mx_AppPermissionButton'
2017-07-26 11:28:43 +01:00
type='button'
2017-07-28 16:42:07 +01:00
value={_t('Allow')}
2017-07-26 11:28:43 +01:00
onClick={this.props.onPermissionGranted}
/>
</div>
);
}
}
AppPermission.propTypes = {
isRoomEncrypted: PropTypes.bool,
2017-07-26 11:28:43 +01:00
url: PropTypes.string.isRequired,
onPermissionGranted: PropTypes.func.isRequired,
};
2017-07-28 16:23:38 +01:00
AppPermission.defaultProps = {
isRoomEncrypted: false,
2017-07-26 11:28:43 +01:00
onPermissionGranted: function() {},
};