Migrate IntegrationManager to TypeScript

pull/21833/head
Germain Souquet 2021-08-14 11:27:17 +02:00
parent dfd986751f
commit 447beb8294
1 changed files with 32 additions and 29 deletions

View File

@ -1,6 +1,7 @@
/*
Copyright 2015, 2016 OpenMarket Ltd
Copyright 2019 The Matrix.org Foundation C.I.C.
Copyright 2021 New Vector Ltd
Licensed under the Apache License, Version 2.0 (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 PropTypes from 'prop-types';
import * as sdk from '../../../index';
import { _t } from '../../../languageHandler';
import dis from '../../../dispatcher/dispatcher';
import { Key } from "../../../Keyboard";
import { replaceableComponent } from "../../../utils/replaceableComponent";
import { ActionPayload } from '../../../dispatcher/payloads';
@replaceableComponent("views.settings.IntegrationManager")
export default class IntegrationManager extends React.Component {
static propTypes = {
interface IProps {
// 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
loading: PropTypes.bool.isRequired,
loading: boolean;
// The source URL to load
url: PropTypes.string,
url?: string;
// 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,
loading: false,
};
constructor(props) {
super(props);
this.state = {
public state = {
errored: false,
};
}
componentDidMount() {
public componentDidMount(): void {
this.dispatcherRef = dis.register(this.onAction);
document.addEventListener("keydown", this.onKeyDown);
}
componentWillUnmount() {
public componentWillUnmount(): void {
dis.unregister(this.dispatcherRef);
document.removeEventListener("keydown", this.onKeyDown);
}
onKeyDown = (ev) => {
private onKeyDown = (ev: KeyboardEvent): void => {
if (ev.key === Key.ESCAPE) {
ev.stopPropagation();
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') {
this.props.onFinished();
}
};
onError = () => {
private onError = (): void => {
this.setState({ errored: true });
};
render() {
public render(): JSX.Element {
if (this.props.loading) {
const Spinner = sdk.getComponent("elements.Spinner");
return (