From f62e0795f030d815563aef72dfab36ed1a97b74c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Tue, 21 Sep 2021 12:51:47 +0200 Subject: [PATCH] Convert NotificationsSettingsTab to TS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- ...ingsTab.js => NotificationSettingsTab.tsx} | 57 ++++++++++--------- 1 file changed, 31 insertions(+), 26 deletions(-) rename src/components/views/settings/tabs/room/{NotificationSettingsTab.js => NotificationSettingsTab.tsx} (81%) diff --git a/src/components/views/settings/tabs/room/NotificationSettingsTab.js b/src/components/views/settings/tabs/room/NotificationSettingsTab.tsx similarity index 81% rename from src/components/views/settings/tabs/room/NotificationSettingsTab.js rename to src/components/views/settings/tabs/room/NotificationSettingsTab.tsx index 9200fb65d1..32453b5a25 100644 --- a/src/components/views/settings/tabs/room/NotificationSettingsTab.js +++ b/src/components/views/settings/tabs/room/NotificationSettingsTab.tsx @@ -15,7 +15,6 @@ limitations under the License. */ import React, { createRef } from 'react'; -import PropTypes from 'prop-types'; import { _t } from "../../../../../languageHandler"; import { MatrixClientPeg } from "../../../../../MatrixClientPeg"; import AccessibleButton from "../../../elements/AccessibleButton"; @@ -24,16 +23,21 @@ import SettingsStore from '../../../../../settings/SettingsStore'; import { SettingLevel } from "../../../../../settings/SettingLevel"; import { replaceableComponent } from "../../../../../utils/replaceableComponent"; +interface IProps { + roomId: string; +} + +interface IState { + currentSound: string; + uploadedFile: File; +} + @replaceableComponent("views.settings.tabs.room.NotificationsSettingsTab") -export default class NotificationsSettingsTab extends React.Component { - static propTypes = { - roomId: PropTypes.string.isRequired, - }; +export default class NotificationsSettingsTab extends React.Component { + private soundUpload = createRef(); - _soundUpload = createRef(); - - constructor() { - super(); + constructor(props: IProps) { + super(props); this.state = { currentSound: "default", @@ -42,7 +46,8 @@ export default class NotificationsSettingsTab extends React.Component { } // TODO: [REACT-WARNING] Replace component with real class, use constructor for refs - UNSAFE_componentWillMount() { // eslint-disable-line camelcase + // eslint-disable-next-line @typescript-eslint/naming-convention, camelcase + public UNSAFE_componentWillMount(): void { const soundData = Notifier.getSoundForRoom(this.props.roomId); if (!soundData) { return; @@ -50,14 +55,14 @@ export default class NotificationsSettingsTab extends React.Component { this.setState({ currentSound: soundData.name || soundData.url }); } - async _triggerUploader(e) { + private triggerUploader = async (e: React.MouseEvent): Promise => { e.stopPropagation(); e.preventDefault(); - this._soundUpload.current.click(); - } + this.soundUpload.current.click(); + }; - async _onSoundUploadChanged(e) { + private onSoundUploadChanged = (e: React.ChangeEvent): Promise => { if (!e.target.files || !e.target.files.length) { this.setState({ uploadedFile: null, @@ -69,23 +74,23 @@ export default class NotificationsSettingsTab extends React.Component { this.setState({ uploadedFile: file, }); - } + }; - async _onClickSaveSound(e) { + private onClickSaveSound = async (e: React.MouseEvent): Promise => { e.stopPropagation(); e.preventDefault(); try { - await this._saveSound(); + await this.saveSound(); } catch (ex) { console.error( `Unable to save notification sound for ${this.props.roomId}`, ); console.error(ex); } - } + }; - async _saveSound() { + private async saveSound(): Promise { if (!this.state.uploadedFile) { return; } @@ -122,7 +127,7 @@ export default class NotificationsSettingsTab extends React.Component { }); } - _clearSound(e) { + private clearSound = (e: React.MouseEvent): void => { e.stopPropagation(); e.preventDefault(); SettingsStore.setValue( @@ -135,9 +140,9 @@ export default class NotificationsSettingsTab extends React.Component { this.setState({ currentSound: "default", }); - } + }; - render() { + public render(): JSX.Element { let currentUploadedFile = null; if (this.state.uploadedFile) { currentUploadedFile = ( @@ -154,23 +159,23 @@ export default class NotificationsSettingsTab extends React.Component { { _t("Sounds") }
{ _t("Notification sound") }: { this.state.currentSound }
- + { _t("Reset") }

{ _t("Set a new custom sound") }

- +
{ currentUploadedFile } - + { _t("Browse") } - + { _t("Save") }