Migrate IntegrationManager to TypeScript

This commit is contained in:
Germain Souquet 2021-08-14 11:27:17 +02:00
parent dfd986751f
commit 447beb8294

View file

@ -1,6 +1,7 @@
/* /*
Copyright 2015, 2016 OpenMarket Ltd Copyright 2015, 2016 OpenMarket Ltd
Copyright 2019 The Matrix.org Foundation C.I.C. Copyright 2019 The Matrix.org Foundation C.I.C.
Copyright 2021 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -16,53 +17,55 @@ limitations under the License.
*/ */
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types';
import * as sdk from '../../../index'; import * as sdk from '../../../index';
import { _t } from '../../../languageHandler'; import { _t } from '../../../languageHandler';
import dis from '../../../dispatcher/dispatcher'; import dis from '../../../dispatcher/dispatcher';
import { Key } from "../../../Keyboard"; import { Key } from "../../../Keyboard";
import { replaceableComponent } from "../../../utils/replaceableComponent"; import { replaceableComponent } from "../../../utils/replaceableComponent";
import { ActionPayload } from '../../../dispatcher/payloads';
@replaceableComponent("views.settings.IntegrationManager") interface IProps {
export default class IntegrationManager extends React.Component {
static propTypes = {
// false to display an error saying that we couldn't connect to the integration manager // false to display an error saying that we couldn't connect to the integration manager
connected: PropTypes.bool.isRequired, connected: boolean;
// true to display a loading spinner // true to display a loading spinner
loading: PropTypes.bool.isRequired, loading: boolean;
// The source URL to load // The source URL to load
url: PropTypes.string, url?: string;
// callback when the manager is dismissed // callback when the manager is dismissed
onFinished: PropTypes.func.isRequired, onFinished: () => void;
}; }
static defaultProps = { interface IState {
errored: boolean;
}
@replaceableComponent("views.settings.IntegrationManager")
export default class IntegrationManager extends React.Component<IProps, IState> {
private dispatcherRef: string;
public static defaultProps = {
connected: true, connected: true,
loading: false, loading: false,
}; };
constructor(props) { public state = {
super(props);
this.state = {
errored: false, errored: false,
}; };
}
componentDidMount() { public componentDidMount(): void {
this.dispatcherRef = dis.register(this.onAction); this.dispatcherRef = dis.register(this.onAction);
document.addEventListener("keydown", this.onKeyDown); document.addEventListener("keydown", this.onKeyDown);
} }
componentWillUnmount() { public componentWillUnmount(): void {
dis.unregister(this.dispatcherRef); dis.unregister(this.dispatcherRef);
document.removeEventListener("keydown", this.onKeyDown); document.removeEventListener("keydown", this.onKeyDown);
} }
onKeyDown = (ev) => { private onKeyDown = (ev: KeyboardEvent): void => {
if (ev.key === Key.ESCAPE) { if (ev.key === Key.ESCAPE) {
ev.stopPropagation(); ev.stopPropagation();
ev.preventDefault(); ev.preventDefault();
@ -70,17 +73,17 @@ export default class IntegrationManager extends React.Component {
} }
}; };
onAction = (payload) => { private onAction = (payload: ActionPayload): void => {
if (payload.action === 'close_scalar') { if (payload.action === 'close_scalar') {
this.props.onFinished(); this.props.onFinished();
} }
}; };
onError = () => { private onError = (): void => {
this.setState({ errored: true }); this.setState({ errored: true });
}; };
render() { public render(): JSX.Element {
if (this.props.loading) { if (this.props.loading) {
const Spinner = sdk.getComponent("elements.Spinner"); const Spinner = sdk.getComponent("elements.Spinner");
return ( return (