2019-01-18 20:22:36 -07:00
|
|
|
/*
|
|
|
|
|
Copyright 2019 New Vector 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';
|
|
|
|
|
import {_t} from "../../../../languageHandler";
|
2019-01-21 17:27:43 -07:00
|
|
|
import MatrixClientPeg from "../../../../MatrixClientPeg";
|
|
|
|
|
import Field from "../../elements/Field";
|
|
|
|
|
import AccessibleButton from "../../elements/AccessibleButton";
|
2019-01-18 20:22:36 -07:00
|
|
|
|
|
|
|
|
export default class GeneralSettingsTab extends React.Component {
|
2019-01-21 17:27:43 -07:00
|
|
|
constructor() {
|
|
|
|
|
super();
|
|
|
|
|
|
|
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
|
this.state = {
|
|
|
|
|
userId: client.getUserId(),
|
|
|
|
|
displayName: client.getUser(client.getUserId()).displayName,
|
|
|
|
|
enableProfileSave: false,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_saveProfile = async (e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
if (!this.state.enableProfileSave) return;
|
|
|
|
|
this.setState({enableProfileSave: false});
|
|
|
|
|
|
|
|
|
|
// TODO: What do we do about errors?
|
|
|
|
|
await MatrixClientPeg.get().setDisplayName(this.state.displayName);
|
|
|
|
|
|
|
|
|
|
// TODO: Support avatars
|
|
|
|
|
|
|
|
|
|
this.setState({enableProfileSave: true});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_onDisplayNameChanged = (e) => {
|
|
|
|
|
this.setState({
|
|
|
|
|
displayName: e.target.value,
|
|
|
|
|
enableProfileSave: true,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_renderProfileSection() {
|
2019-01-21 17:49:48 -07:00
|
|
|
// TODO: Ditch avatar placeholder and use the real thing
|
2019-01-21 17:27:43 -07:00
|
|
|
const form = (
|
|
|
|
|
<form onSubmit={this._saveProfile} autoComplete={false} noValidate={true}>
|
|
|
|
|
<div className="mx_GeneralSettingsTab_profile">
|
|
|
|
|
<div className="mx_GeneralSettingsTab_profileControls">
|
|
|
|
|
<p className="mx_GeneralSettingsTab_profileUsername">{this.state.userId}</p>
|
|
|
|
|
<Field id="profileDisplayName" label={_t("Display Name")}
|
|
|
|
|
type="text" value={this.state.displayName} autocomplete="off"
|
2019-01-21 17:49:48 -07:00
|
|
|
onChange={this._onDisplayNameChanged} />
|
2019-01-21 17:27:43 -07:00
|
|
|
</div>
|
|
|
|
|
<div className="mx_GeneralSettingsTab_profileAvatar">
|
2019-01-21 17:49:48 -07:00
|
|
|
<div />
|
2019-01-21 17:27:43 -07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<AccessibleButton onClick={this._saveProfile} kind="primary"
|
2019-01-21 17:49:48 -07:00
|
|
|
disabled={!this.state.enableProfileSave}>
|
2019-01-21 17:27:43 -07:00
|
|
|
{_t("Save")}
|
|
|
|
|
</AccessibleButton>
|
2019-01-22 10:36:47 -07:00
|
|
|
<div>FLAIR</div>
|
2019-01-21 17:27:43 -07:00
|
|
|
</form>
|
|
|
|
|
);
|
|
|
|
|
|
2019-01-21 20:55:40 -07:00
|
|
|
return (
|
|
|
|
|
<div className="mx_SettingsTab_section">
|
2019-01-21 17:27:43 -07:00
|
|
|
<span className="mx_SettingsTab_subheading">{_t("Profile")}</span>
|
|
|
|
|
{form}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-22 10:36:47 -07:00
|
|
|
_renderAccountSection() {
|
|
|
|
|
return (
|
|
|
|
|
<div className="mx_SettingsTab_section">
|
|
|
|
|
<span className="mx_SettingsTab_subheading">{_t("Account")}</span>
|
|
|
|
|
<p>ACCOUNT SECTION</p>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_renderLanguageSection() {
|
|
|
|
|
return (
|
|
|
|
|
<div className="mx_SettingsTab_section">
|
|
|
|
|
<span className="mx_SettingsTab_subheading">{_t("Language and region")}</span>
|
|
|
|
|
<p>LANGUAGE SECTION</p>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_renderThemeSection() {
|
|
|
|
|
return (
|
|
|
|
|
<div className="mx_SettingsTab_section">
|
|
|
|
|
<span className="mx_SettingsTab_subheading">{_t("Theme")}</span>
|
|
|
|
|
<p>THEME SECTION</p>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_renderManagementSection() {
|
|
|
|
|
return (
|
|
|
|
|
<div className="mx_SettingsTab_section">
|
|
|
|
|
<span className="mx_SettingsTab_subheading">{_t("Account management")}</span>
|
|
|
|
|
<p>MANAGEMENT SECTION</p>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-18 20:22:36 -07:00
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<div className="mx_SettingsTab">
|
|
|
|
|
<div className="mx_SettingsTab_heading">{_t("General")}</div>
|
2019-01-21 17:27:43 -07:00
|
|
|
{this._renderProfileSection()}
|
2019-01-22 10:36:47 -07:00
|
|
|
{this._renderAccountSection()}
|
|
|
|
|
{this._renderLanguageSection()}
|
|
|
|
|
{this._renderThemeSection()}
|
|
|
|
|
{this._renderManagementSection()}
|
2019-01-18 20:22:36 -07:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|