mirror of https://github.com/vector-im/riot-web
Migrate DevicesPanelEntry to TypeScript
parent
fb6a6370e7
commit
dfd986751f
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2016 OpenMarket Ltd
|
Copyright 2016 OpenMarket Ltd
|
||||||
|
Copyright 2021 New Vector Ltd
|
||||||
|
|
||||||
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,7 +16,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import { IMyDevice } from 'matrix-js-sdk/src';
|
||||||
|
|
||||||
import * as sdk from '../../../index';
|
import * as sdk from '../../../index';
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
|
@ -24,21 +25,19 @@ import { formatDate } from '../../../DateUtils';
|
||||||
import StyledCheckbox from '../elements/StyledCheckbox';
|
import StyledCheckbox from '../elements/StyledCheckbox';
|
||||||
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
||||||
|
|
||||||
|
interface IProps {
|
||||||
|
device?: IMyDevice;
|
||||||
|
onDeviceToggled?: (device: IMyDevice) => void;
|
||||||
|
selected?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
@replaceableComponent("views.settings.DevicesPanelEntry")
|
@replaceableComponent("views.settings.DevicesPanelEntry")
|
||||||
export default class DevicesPanelEntry extends React.Component {
|
export default class DevicesPanelEntry extends React.Component<IProps> {
|
||||||
constructor(props) {
|
public static defaultProps = {
|
||||||
super(props);
|
onDeviceToggled: () => {},
|
||||||
|
};
|
||||||
|
|
||||||
this._unmounted = false;
|
private onDisplayNameChanged = (value: string): Promise<{}> => {
|
||||||
this.onDeviceToggled = this.onDeviceToggled.bind(this);
|
|
||||||
this._onDisplayNameChanged = this._onDisplayNameChanged.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
componentWillUnmount() {
|
|
||||||
this._unmounted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
_onDisplayNameChanged(value) {
|
|
||||||
const device = this.props.device;
|
const device = this.props.device;
|
||||||
return MatrixClientPeg.get().setDeviceDetails(device.device_id, {
|
return MatrixClientPeg.get().setDeviceDetails(device.device_id, {
|
||||||
display_name: value,
|
display_name: value,
|
||||||
|
@ -46,13 +45,13 @@ export default class DevicesPanelEntry extends React.Component {
|
||||||
console.error("Error setting session display name", e);
|
console.error("Error setting session display name", e);
|
||||||
throw new Error(_t("Failed to set display name"));
|
throw new Error(_t("Failed to set display name"));
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
onDeviceToggled() {
|
private onDeviceToggled = (): void => {
|
||||||
this.props.onDeviceToggled(this.props.device);
|
this.props.onDeviceToggled(this.props.device);
|
||||||
}
|
};
|
||||||
|
|
||||||
render() {
|
public render(): JSX.Element {
|
||||||
const EditableTextContainer = sdk.getComponent('elements.EditableTextContainer');
|
const EditableTextContainer = sdk.getComponent('elements.EditableTextContainer');
|
||||||
|
|
||||||
const device = this.props.device;
|
const device = this.props.device;
|
||||||
|
@ -76,7 +75,7 @@ export default class DevicesPanelEntry extends React.Component {
|
||||||
</div>
|
</div>
|
||||||
<div className="mx_DevicesPanel_deviceName">
|
<div className="mx_DevicesPanel_deviceName">
|
||||||
<EditableTextContainer initialValue={device.display_name}
|
<EditableTextContainer initialValue={device.display_name}
|
||||||
onSubmit={this._onDisplayNameChanged}
|
onSubmit={this.onDisplayNameChanged}
|
||||||
placeholder={device.device_id}
|
placeholder={device.device_id}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -90,12 +89,3 @@ export default class DevicesPanelEntry extends React.Component {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DevicesPanelEntry.propTypes = {
|
|
||||||
device: PropTypes.object.isRequired,
|
|
||||||
onDeviceToggled: PropTypes.func,
|
|
||||||
};
|
|
||||||
|
|
||||||
DevicesPanelEntry.defaultProps = {
|
|
||||||
onDeviceToggled: function() {},
|
|
||||||
};
|
|
Loading…
Reference in New Issue