Convert AdvancedRoomSettingsTab to Typescript
This commit is contained in:
parent
4725a9e8fa
commit
9454a4e6c7
1 changed files with 47 additions and 40 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2019 New Vector Ltd
|
Copyright 2019, 2021 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
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.
|
||||||
|
@ -15,68 +15,75 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import { _t } from "../../../../../languageHandler";
|
import { _t } from "../../../../../languageHandler";
|
||||||
import { MatrixClientPeg } from "../../../../../MatrixClientPeg";
|
import { MatrixClientPeg } from "../../../../../MatrixClientPeg";
|
||||||
import * as sdk from "../../../../..";
|
|
||||||
import AccessibleButton from "../../../elements/AccessibleButton";
|
import AccessibleButton from "../../../elements/AccessibleButton";
|
||||||
|
import RoomUpgradeDialog from "../../../dialogs/RoomUpgradeDialog";
|
||||||
|
import DevtoolsDialog from "../../../dialogs/DevtoolsDialog";
|
||||||
import Modal from "../../../../../Modal";
|
import Modal from "../../../../../Modal";
|
||||||
import dis from "../../../../../dispatcher/dispatcher";
|
import dis from "../../../../../dispatcher/dispatcher";
|
||||||
import { replaceableComponent } from "../../../../../utils/replaceableComponent";
|
import { replaceableComponent } from "../../../../../utils/replaceableComponent";
|
||||||
|
|
||||||
@replaceableComponent("views.settings.tabs.room.AdvancedRoomSettingsTab")
|
interface IProps {
|
||||||
export default class AdvancedRoomSettingsTab extends React.Component {
|
roomId: string;
|
||||||
static propTypes = {
|
closeSettingsFn(): void;
|
||||||
roomId: PropTypes.string.isRequired,
|
}
|
||||||
closeSettingsFn: PropTypes.func.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor(props) {
|
interface IRecommendedVersion {
|
||||||
super(props);
|
version: string;
|
||||||
|
needsUpgrade: boolean;
|
||||||
|
urgent: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IState {
|
||||||
|
upgradeRecommendation?: IRecommendedVersion;
|
||||||
|
oldRoomId?: string;
|
||||||
|
oldEventId?: string;
|
||||||
|
upgraded?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
@replaceableComponent("views.settings.tabs.room.AdvancedRoomSettingsTab")
|
||||||
|
export default class AdvancedRoomSettingsTab extends React.Component<IProps, IState> {
|
||||||
|
constructor(props, context) {
|
||||||
|
super(props, context);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
// This is eventually set to the value of room.getRecommendedVersion()
|
// This is eventually set to the value of room.getRecommendedVersion()
|
||||||
upgradeRecommendation: null,
|
upgradeRecommendation: null,
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: [REACT-WARNING] Move this to constructor
|
|
||||||
UNSAFE_componentWillMount() { // eslint-disable-line camelcase
|
|
||||||
// we handle lack of this object gracefully later, so don't worry about it failing here.
|
// we handle lack of this object gracefully later, so don't worry about it failing here.
|
||||||
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
||||||
room.getRecommendedVersion().then((v) => {
|
room.getRecommendedVersion().then((v) => {
|
||||||
const tombstone = room.currentState.getStateEvents("m.room.tombstone", "");
|
const tombstone = room.currentState.getStateEvents("m.room.tombstone", "");
|
||||||
|
|
||||||
const additionalStateChanges = {};
|
const additionalStateChanges: Partial<IState> = {};
|
||||||
const createEvent = room.currentState.getStateEvents("m.room.create", "");
|
const createEvent = room.currentState.getStateEvents("m.room.create", "");
|
||||||
const predecessor = createEvent ? createEvent.getContent().predecessor : null;
|
const predecessor = createEvent ? createEvent.getContent().predecessor : null;
|
||||||
if (predecessor && predecessor.room_id) {
|
if (predecessor && predecessor.room_id) {
|
||||||
additionalStateChanges['oldRoomId'] = predecessor.room_id;
|
additionalStateChanges.oldRoomId = predecessor.room_id;
|
||||||
additionalStateChanges['oldEventId'] = predecessor.event_id;
|
additionalStateChanges.oldEventId = predecessor.event_id;
|
||||||
additionalStateChanges['hasPreviousRoom'] = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
upgraded: tombstone && tombstone.getContent().replacement_room,
|
upgraded: !!tombstone?.getContent().replacement_room,
|
||||||
upgradeRecommendation: v,
|
upgradeRecommendation: v,
|
||||||
...additionalStateChanges,
|
...additionalStateChanges,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_upgradeRoom = (e) => {
|
private upgradeRoom = (e) => {
|
||||||
const RoomUpgradeDialog = sdk.getComponent('dialogs.RoomUpgradeDialog');
|
|
||||||
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
||||||
Modal.createTrackedDialog('Upgrade Room Version', '', RoomUpgradeDialog, {room: room});
|
Modal.createTrackedDialog('Upgrade Room Version', '', RoomUpgradeDialog, {room: room});
|
||||||
};
|
};
|
||||||
|
|
||||||
_openDevtools = (e) => {
|
private openDevtools = (e) => {
|
||||||
const DevtoolsDialog = sdk.getComponent('dialogs.DevtoolsDialog');
|
|
||||||
Modal.createDialog(DevtoolsDialog, {roomId: this.props.roomId});
|
Modal.createDialog(DevtoolsDialog, {roomId: this.props.roomId});
|
||||||
};
|
};
|
||||||
|
|
||||||
_onOldRoomClicked = (e) => {
|
private onOldRoomClicked = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
|
@ -113,7 +120,7 @@ export default class AdvancedRoomSettingsTab extends React.Component {
|
||||||
},
|
},
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
<AccessibleButton onClick={this._upgradeRoom} kind='primary'>
|
<AccessibleButton onClick={this.upgradeRoom} kind='primary'>
|
||||||
{_t("Upgrade this room to the recommended room version")}
|
{_t("Upgrade this room to the recommended room version")}
|
||||||
</AccessibleButton>
|
</AccessibleButton>
|
||||||
</div>
|
</div>
|
||||||
|
@ -121,12 +128,12 @@ export default class AdvancedRoomSettingsTab extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
let oldRoomLink;
|
let oldRoomLink;
|
||||||
if (this.state.hasPreviousRoom) {
|
if (this.state.oldRoomId) {
|
||||||
let name = _t("this room");
|
let name = _t("this room");
|
||||||
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
const room = MatrixClientPeg.get().getRoom(this.props.roomId);
|
||||||
if (room && room.name) name = room.name;
|
if (room && room.name) name = room.name;
|
||||||
oldRoomLink = (
|
oldRoomLink = (
|
||||||
<AccessibleButton element='a' onClick={this._onOldRoomClicked}>
|
<AccessibleButton element='a' onClick={this.onOldRoomClicked}>
|
||||||
{ _t("View older messages in %(roomName)s.", { roomName: name }) }
|
{ _t("View older messages in %(roomName)s.", { roomName: name }) }
|
||||||
</AccessibleButton>
|
</AccessibleButton>
|
||||||
);
|
);
|
||||||
|
@ -154,7 +161,7 @@ export default class AdvancedRoomSettingsTab extends React.Component {
|
||||||
</div>
|
</div>
|
||||||
<div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'>
|
<div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'>
|
||||||
<span className='mx_SettingsTab_subheading'>{ _t("Developer options") }</span>
|
<span className='mx_SettingsTab_subheading'>{ _t("Developer options") }</span>
|
||||||
<AccessibleButton onClick={this._openDevtools} kind='primary'>
|
<AccessibleButton onClick={this.openDevtools} kind='primary'>
|
||||||
{ _t("Open Devtools") }
|
{ _t("Open Devtools") }
|
||||||
</AccessibleButton>
|
</AccessibleButton>
|
||||||
</div>
|
</div>
|
Loading…
Reference in a new issue