diff --git a/src/components/views/rooms/ReplyPreview.js b/src/components/views/rooms/ReplyPreview.tsx similarity index 81% rename from src/components/views/rooms/ReplyPreview.js rename to src/components/views/rooms/ReplyPreview.tsx index c7d19e58db..9682ce2bfe 100644 --- a/src/components/views/rooms/ReplyPreview.js +++ b/src/components/views/rooms/ReplyPreview.tsx @@ -22,6 +22,8 @@ import PropTypes from "prop-types"; import { RoomPermalinkCreator } from "../../../utils/permalinks/Permalinks"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import ReplyTile from './ReplyTile'; +import { MatrixEvent } from 'matrix-js-sdk/src/models/event'; +import { EventSubscription } from 'fbemitter'; function cancelQuoting() { dis.dispatch({ @@ -30,41 +32,46 @@ function cancelQuoting() { }); } +interface IProps { + permalinkCreator: RoomPermalinkCreator, +} + +interface IState { + event: MatrixEvent +} + @replaceableComponent("views.rooms.ReplyPreview") -export default class ReplyPreview extends React.Component { - static propTypes = { - permalinkCreator: PropTypes.instanceOf(RoomPermalinkCreator).isRequired, - }; +export default class ReplyPreview extends React.Component { + private unmounted = false; + private roomStoreToken: EventSubscription; constructor(props) { super(props); - this.unmounted = false; this.state = { event: RoomViewStore.getQuotingEvent(), }; - this._onRoomViewStoreUpdate = this._onRoomViewStoreUpdate.bind(this); - this._roomStoreToken = RoomViewStore.addListener(this._onRoomViewStoreUpdate); + this.roomStoreToken = RoomViewStore.addListener(this.onRoomViewStoreUpdate); } componentWillUnmount() { this.unmounted = true; // Remove RoomStore listener - if (this._roomStoreToken) { - this._roomStoreToken.remove(); + if (this.roomStoreToken) { + this.roomStoreToken.remove(); } } - _onRoomViewStoreUpdate() { + private onRoomViewStoreUpdate = (): void => { if (this.unmounted) return; const event = RoomViewStore.getQuotingEvent(); if (this.state.event !== event) { this.setState({ event }); } - } + }; render() { if (!this.state.event) return null;