Merge pull request #5373 from matrix-org/dbkr/auxpanel_typescript

Convert AuxPanel to TypeScript
This commit is contained in:
David Baker 2020-10-30 17:45:00 +00:00 committed by GitHub
commit a0c07907b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 32 deletions

View file

@ -12,7 +12,6 @@ src/components/views/elements/AddressSelector.js
src/components/views/elements/DirectorySearchBox.js src/components/views/elements/DirectorySearchBox.js
src/components/views/messages/MFileBody.js src/components/views/messages/MFileBody.js
src/components/views/messages/TextualBody.js src/components/views/messages/TextualBody.js
src/components/views/rooms/AuxPanel.js
src/components/views/rooms/LinkPreviewWidget.js src/components/views/rooms/LinkPreviewWidget.js
src/components/views/rooms/MemberList.js src/components/views/rooms/MemberList.js
src/components/views/rooms/RoomPreviewBar.js src/components/views/rooms/RoomPreviewBar.js

View file

@ -1,6 +1,5 @@
/* /*
Copyright 2015, 2016 OpenMarket Ltd Copyright 2015, 2016, 2017, 2020 The Matrix.org Foundation C.I.C.
Copyright 2017 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,8 +15,8 @@ limitations under the License.
*/ */
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types';
import {MatrixClientPeg} from "../../../MatrixClientPeg"; import {MatrixClientPeg} from "../../../MatrixClientPeg";
import { Room } from 'matrix-js-sdk/src/models/room'
import * as sdk from '../../../index'; import * as sdk from '../../../index';
import dis from "../../../dispatcher/dispatcher"; import dis from "../../../dispatcher/dispatcher";
import * as ObjectUtils from '../../../ObjectUtils'; import * as ObjectUtils from '../../../ObjectUtils';
@ -29,28 +28,42 @@ import SettingsStore from "../../../settings/SettingsStore";
import AutoHideScrollbar from "../../structures/AutoHideScrollbar"; import AutoHideScrollbar from "../../structures/AutoHideScrollbar";
import CallView from "../voip/CallView"; import CallView from "../voip/CallView";
import {UIFeature} from "../../../settings/UIFeature"; import {UIFeature} from "../../../settings/UIFeature";
import { ResizeNotifier } from "../../../utils/ResizeNotifier";
interface IProps {
export default class AuxPanel extends React.Component {
static propTypes = {
// js-sdk room object // js-sdk room object
room: PropTypes.object.isRequired, room: Room,
userId: PropTypes.string.isRequired, userId: string,
showApps: PropTypes.bool, // Render apps showApps: boolean, // Render apps
// set to true to show the file drop target // set to true to show the file drop target
draggingFile: PropTypes.bool, draggingFile: boolean,
// maxHeight attribute for the aux panel and the video // maxHeight attribute for the aux panel and the video
// therein // therein
maxHeight: PropTypes.number, maxHeight: number,
// a callback which is called when the content of the aux panel changes // a callback which is called when the content of the aux panel changes
// content in a way that is likely to make it change size. // content in a way that is likely to make it change size.
onResize: PropTypes.func, onResize: () => void,
fullHeight: PropTypes.bool, fullHeight: boolean,
};
resizeNotifier: ResizeNotifier,
}
interface Counter {
title: string,
value: number,
link: string,
severity: string,
stateKey: string,
}
interface IState {
counters: Counter[],
}
export default class AuxPanel extends React.Component<IProps, IState> {
static defaultProps = { static defaultProps = {
showApps: true, showApps: true,
}; };
@ -104,7 +117,7 @@ export default class AuxPanel extends React.Component {
}, 500); }, 500);
_computeCounters() { _computeCounters() {
let counters = []; const counters = [];
if (this.props.room && SettingsStore.getValue("feature_state_counters")) { if (this.props.room && SettingsStore.getValue("feature_state_counters")) {
const stateEvs = this.props.room.currentState.getStateEvents('re.jki.counter'); const stateEvs = this.props.room.currentState.getStateEvents('re.jki.counter');
@ -112,7 +125,7 @@ export default class AuxPanel extends React.Component {
return a.getStateKey() < b.getStateKey(); return a.getStateKey() < b.getStateKey();
}); });
stateEvs.forEach((ev, idx) => { for (const ev of stateEvs) {
const title = ev.getContent().title; const title = ev.getContent().title;
const value = ev.getContent().value; const value = ev.getContent().value;
const link = ev.getContent().link; const link = ev.getContent().link;
@ -123,14 +136,14 @@ export default class AuxPanel extends React.Component {
// zero) // zero)
if (title && value !== undefined) { if (title && value !== undefined) {
counters.push({ counters.push({
"title": title, title,
"value": value, value,
"link": link, link,
"severity": severity, severity,
"stateKey": stateKey stateKey,
}) })
} }
}); }
} }
return counters; return counters;
@ -143,8 +156,7 @@ export default class AuxPanel extends React.Component {
if (this.props.draggingFile) { if (this.props.draggingFile) {
fileDropTarget = ( fileDropTarget = (
<div className="mx_RoomView_fileDropTarget"> <div className="mx_RoomView_fileDropTarget">
<div className="mx_RoomView_fileDropTargetLabel" <div className="mx_RoomView_fileDropTargetLabel" title={_t("Drop File Here")}>
title={_t("Drop File Here")}>
<TintableSvg src={require("../../../../res/img/upload-big.svg")} width="45" height="59" /> <TintableSvg src={require("../../../../res/img/upload-big.svg")} width="45" height="59" />
<br /> <br />
{ _t("Drop file here to upload") } { _t("Drop file here to upload") }
@ -208,7 +220,7 @@ export default class AuxPanel extends React.Component {
<span <span
className="m_RoomView_auxPanel_stateViews_delim" className="m_RoomView_auxPanel_stateViews_delim"
key={"delim" + idx} key={"delim" + idx}
> </span> > </span>,
); );
}); });
@ -226,7 +238,7 @@ export default class AuxPanel extends React.Component {
"mx_RoomView_auxPanel": true, "mx_RoomView_auxPanel": true,
"mx_RoomView_auxPanel_fullHeight": this.props.fullHeight, "mx_RoomView_auxPanel_fullHeight": this.props.fullHeight,
}); });
const style = {}; const style: React.CSSProperties = {};
if (!this.props.fullHeight) { if (!this.props.fullHeight) {
style.maxHeight = this.props.maxHeight; style.maxHeight = this.props.maxHeight;
} }