From 2a7787e12dccfc16c0533414eaa2d7c0563d8c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sat, 17 Jul 2021 15:09:13 +0200 Subject: [PATCH] Convert ReplyPreview to TS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- .../{ReplyPreview.js => ReplyPreview.tsx} | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) rename src/components/views/rooms/{ReplyPreview.js => ReplyPreview.tsx} (81%) 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;