Convert ReplyPreview to TS

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
pull/21833/head
Šimon Brandner 2021-07-17 15:09:13 +02:00
parent 96acd6c9ef
commit 2a7787e12d
No known key found for this signature in database
GPG Key ID: CC823428E9B582FB
1 changed files with 18 additions and 11 deletions

View File

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