Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit a0c0790

Browse files
authored
Merge pull request #5373 from matrix-org/dbkr/auxpanel_typescript
Convert AuxPanel to TypeScript
2 parents 517e3b5 + f920c1f commit a0c0790

File tree

2 files changed

+43
-32
lines changed

2 files changed

+43
-32
lines changed

.eslintignore.errorfiles

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ src/components/views/elements/AddressSelector.js
1212
src/components/views/elements/DirectorySearchBox.js
1313
src/components/views/messages/MFileBody.js
1414
src/components/views/messages/TextualBody.js
15-
src/components/views/rooms/AuxPanel.js
1615
src/components/views/rooms/LinkPreviewWidget.js
1716
src/components/views/rooms/MemberList.js
1817
src/components/views/rooms/RoomPreviewBar.js

src/components/views/rooms/AuxPanel.js renamed to src/components/views/rooms/AuxPanel.tsx

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
2-
Copyright 2015, 2016 OpenMarket Ltd
3-
Copyright 2017 New Vector Ltd
2+
Copyright 2015, 2016, 2017, 2020 The Matrix.org Foundation C.I.C.
43
54
Licensed under the Apache License, Version 2.0 (the "License");
65
you may not use this file except in compliance with the License.
@@ -16,8 +15,8 @@ limitations under the License.
1615
*/
1716

1817
import React from 'react';
19-
import PropTypes from 'prop-types';
2018
import {MatrixClientPeg} from "../../../MatrixClientPeg";
19+
import { Room } from 'matrix-js-sdk/src/models/room'
2120
import * as sdk from '../../../index';
2221
import dis from "../../../dispatcher/dispatcher";
2322
import * as ObjectUtils from '../../../ObjectUtils';
@@ -29,28 +28,42 @@ import SettingsStore from "../../../settings/SettingsStore";
2928
import AutoHideScrollbar from "../../structures/AutoHideScrollbar";
3029
import CallView from "../voip/CallView";
3130
import {UIFeature} from "../../../settings/UIFeature";
31+
import { ResizeNotifier } from "../../../utils/ResizeNotifier";
3232

33+
interface IProps {
34+
// js-sdk room object
35+
room: Room,
36+
userId: string,
37+
showApps: boolean, // Render apps
3338

34-
export default class AuxPanel extends React.Component {
35-
static propTypes = {
36-
// js-sdk room object
37-
room: PropTypes.object.isRequired,
38-
userId: PropTypes.string.isRequired,
39-
showApps: PropTypes.bool, // Render apps
39+
// set to true to show the file drop target
40+
draggingFile: boolean,
4041

41-
// set to true to show the file drop target
42-
draggingFile: PropTypes.bool,
42+
// maxHeight attribute for the aux panel and the video
43+
// therein
44+
maxHeight: number,
4345

44-
// maxHeight attribute for the aux panel and the video
45-
// therein
46-
maxHeight: PropTypes.number,
46+
// a callback which is called when the content of the aux panel changes
47+
// content in a way that is likely to make it change size.
48+
onResize: () => void,
49+
fullHeight: boolean,
4750

48-
// a callback which is called when the content of the aux panel changes
49-
// content in a way that is likely to make it change size.
50-
onResize: PropTypes.func,
51-
fullHeight: PropTypes.bool,
52-
};
51+
resizeNotifier: ResizeNotifier,
52+
}
53+
54+
interface Counter {
55+
title: string,
56+
value: number,
57+
link: string,
58+
severity: string,
59+
stateKey: string,
60+
}
5361

62+
interface IState {
63+
counters: Counter[],
64+
}
65+
66+
export default class AuxPanel extends React.Component<IProps, IState> {
5467
static defaultProps = {
5568
showApps: true,
5669
};
@@ -104,15 +117,15 @@ export default class AuxPanel extends React.Component {
104117
}, 500);
105118

106119
_computeCounters() {
107-
let counters = [];
120+
const counters = [];
108121

109122
if (this.props.room && SettingsStore.getValue("feature_state_counters")) {
110123
const stateEvs = this.props.room.currentState.getStateEvents('re.jki.counter');
111124
stateEvs.sort((a, b) => {
112125
return a.getStateKey() < b.getStateKey();
113126
});
114127

115-
stateEvs.forEach((ev, idx) => {
128+
for (const ev of stateEvs) {
116129
const title = ev.getContent().title;
117130
const value = ev.getContent().value;
118131
const link = ev.getContent().link;
@@ -123,14 +136,14 @@ export default class AuxPanel extends React.Component {
123136
// zero)
124137
if (title && value !== undefined) {
125138
counters.push({
126-
"title": title,
127-
"value": value,
128-
"link": link,
129-
"severity": severity,
130-
"stateKey": stateKey
139+
title,
140+
value,
141+
link,
142+
severity,
143+
stateKey,
131144
})
132145
}
133-
});
146+
}
134147
}
135148

136149
return counters;
@@ -143,8 +156,7 @@ export default class AuxPanel extends React.Component {
143156
if (this.props.draggingFile) {
144157
fileDropTarget = (
145158
<div className="mx_RoomView_fileDropTarget">
146-
<div className="mx_RoomView_fileDropTargetLabel"
147-
title={_t("Drop File Here")}>
159+
<div className="mx_RoomView_fileDropTargetLabel" title={_t("Drop File Here")}>
148160
<TintableSvg src={require("../../../../res/img/upload-big.svg")} width="45" height="59" />
149161
<br />
150162
{ _t("Drop file here to upload") }
@@ -208,7 +220,7 @@ export default class AuxPanel extends React.Component {
208220
<span
209221
className="m_RoomView_auxPanel_stateViews_delim"
210222
key={"delim" + idx}
211-
></span>
223+
></span>,
212224
);
213225
});
214226

@@ -226,7 +238,7 @@ export default class AuxPanel extends React.Component {
226238
"mx_RoomView_auxPanel": true,
227239
"mx_RoomView_auxPanel_fullHeight": this.props.fullHeight,
228240
});
229-
const style = {};
241+
const style: React.CSSProperties = {};
230242
if (!this.props.fullHeight) {
231243
style.maxHeight = this.props.maxHeight;
232244
}

0 commit comments

Comments
 (0)