2018-04-11 22:58:04 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2019-06-17 19:38:23 +00:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2018-04-11 22:58:04 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-06-17 19:38:23 +00:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import sdk from '../../../index';
|
|
|
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
|
|
|
import { _t } from '../../../languageHandler';
|
|
|
|
import Modal from '../../../Modal';
|
|
|
|
import dis from '../../../dispatcher';
|
2018-04-11 22:58:04 +00:00
|
|
|
|
2019-06-17 19:38:23 +00:00
|
|
|
export default class IntegrationsManager extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
// the source of the integration manager being embedded
|
|
|
|
src: PropTypes.string.isRequired,
|
2018-04-11 22:58:04 +00:00
|
|
|
|
2019-06-17 19:38:23 +00:00
|
|
|
// callback when the manager is dismissed
|
|
|
|
onFinished: PropTypes.func.isRequired,
|
|
|
|
};
|
2018-04-11 22:58:04 +00:00
|
|
|
|
2019-06-17 19:38:23 +00:00
|
|
|
componentDidMount() {
|
2018-04-11 22:58:04 +00:00
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
|
|
|
document.addEventListener("keydown", this.onKeyDown);
|
2019-06-17 19:38:23 +00:00
|
|
|
}
|
2018-04-11 22:58:04 +00:00
|
|
|
|
2019-06-17 19:38:23 +00:00
|
|
|
componentWillUnmount() {
|
2018-04-11 22:58:04 +00:00
|
|
|
dis.unregister(this.dispatcherRef);
|
|
|
|
document.removeEventListener("keydown", this.onKeyDown);
|
2019-06-17 19:38:23 +00:00
|
|
|
}
|
2018-04-11 22:58:04 +00:00
|
|
|
|
2019-06-17 19:38:23 +00:00
|
|
|
onKeyDown = (ev) => {
|
|
|
|
if (ev.keyCode === 27) { // escape
|
2018-04-11 22:58:04 +00:00
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
this.props.onFinished();
|
|
|
|
}
|
2019-06-17 19:38:23 +00:00
|
|
|
};
|
2018-04-11 22:58:04 +00:00
|
|
|
|
2019-06-17 19:38:23 +00:00
|
|
|
onAction = (payload) => {
|
2018-04-11 22:58:04 +00:00
|
|
|
if (payload.action === 'close_scalar') {
|
|
|
|
this.props.onFinished();
|
|
|
|
}
|
2019-06-17 19:38:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return <iframe src={ this.props.src }></iframe>;
|
|
|
|
}
|
|
|
|
}
|