2016-08-01 15:42:29 +03:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2016-08-01 15:42:29 +03:00
|
|
|
|
|
|
|
import sdk from '../../../index';
|
2017-05-25 13:39:08 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2016-08-01 15:42:29 +03:00
|
|
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
2018-01-10 15:00:11 +03:00
|
|
|
import {formatDate} from '../../../DateUtils';
|
2017-02-21 03:19:49 +03:00
|
|
|
|
2016-08-01 15:42:29 +03:00
|
|
|
export default class DevicesPanelEntry extends React.Component {
|
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this._unmounted = false;
|
2017-11-28 18:23:09 +03:00
|
|
|
this.onDeviceToggled = this.onDeviceToggled.bind(this);
|
2016-08-01 15:42:29 +03:00
|
|
|
this._onDisplayNameChanged = this._onDisplayNameChanged.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this._unmounted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_onDisplayNameChanged(value) {
|
|
|
|
const device = this.props.device;
|
|
|
|
return MatrixClientPeg.get().setDeviceDetails(device.device_id, {
|
|
|
|
display_name: value,
|
|
|
|
}).catch((e) => {
|
|
|
|
console.error("Error setting device display name", e);
|
2017-05-23 17:16:31 +03:00
|
|
|
throw new Error(_t("Failed to set display name"));
|
2016-08-01 15:42:29 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-28 18:23:09 +03:00
|
|
|
onDeviceToggled() {
|
|
|
|
this.props.onDeviceToggled(this.props.device);
|
2016-08-01 15:42:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const EditableTextContainer = sdk.getComponent('elements.EditableTextContainer');
|
|
|
|
|
|
|
|
const device = this.props.device;
|
|
|
|
|
|
|
|
let lastSeen = "";
|
|
|
|
if (device.last_seen_ts) {
|
2018-01-10 15:00:11 +03:00
|
|
|
const lastSeenDate = formatDate(new Date(device.last_seen_ts));
|
2016-08-01 15:42:29 +03:00
|
|
|
lastSeen = device.last_seen_ip + " @ " +
|
|
|
|
lastSeenDate.toLocaleString();
|
|
|
|
}
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
let myDeviceClass = '';
|
2016-09-15 03:55:51 +03:00
|
|
|
if (device.device_id === MatrixClientPeg.get().getDeviceId()) {
|
|
|
|
myDeviceClass = " mx_DevicesPanel_myDevice";
|
|
|
|
}
|
|
|
|
|
2016-08-01 15:42:29 +03:00
|
|
|
return (
|
2017-10-11 19:56:17 +03:00
|
|
|
<div className={"mx_DevicesPanel_device" + myDeviceClass}>
|
2016-08-11 18:16:53 +03:00
|
|
|
<div className="mx_DevicesPanel_deviceId">
|
2017-10-11 19:56:17 +03:00
|
|
|
{ device.device_id }
|
2016-08-11 18:16:53 +03:00
|
|
|
</div>
|
2016-08-01 15:42:29 +03:00
|
|
|
<div className="mx_DevicesPanel_deviceName">
|
|
|
|
<EditableTextContainer initialValue={device.display_name}
|
2016-08-03 16:19:54 +03:00
|
|
|
onSubmit={this._onDisplayNameChanged}
|
|
|
|
placeholder={device.device_id}
|
|
|
|
/>
|
2016-08-01 15:42:29 +03:00
|
|
|
</div>
|
|
|
|
<div className="mx_DevicesPanel_lastSeen">
|
2017-10-11 19:56:17 +03:00
|
|
|
{ lastSeen }
|
2016-08-01 15:42:29 +03:00
|
|
|
</div>
|
|
|
|
<div className="mx_DevicesPanel_deviceButtons">
|
2019-10-03 23:47:19 +03:00
|
|
|
<input type="checkbox" onChange={this.onDeviceToggled} checked={this.props.selected} />
|
2016-08-01 15:42:29 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DevicesPanelEntry.propTypes = {
|
2017-12-26 04:03:18 +03:00
|
|
|
device: PropTypes.object.isRequired,
|
|
|
|
onDeviceToggled: PropTypes.func,
|
2017-02-21 03:19:49 +03:00
|
|
|
};
|
|
|
|
|
2016-08-01 15:42:29 +03:00
|
|
|
DevicesPanelEntry.defaultProps = {
|
2017-11-28 18:23:09 +03:00
|
|
|
onDeviceToggled: function() {},
|
2016-08-01 15:42:29 +03:00
|
|
|
};
|