diff --git a/src/components/structures/GroupView.js b/src/components/structures/GroupView.js
index 30d67202e7..5f7866773d 100644
--- a/src/components/structures/GroupView.js
+++ b/src/components/structures/GroupView.js
@@ -22,6 +22,8 @@ import dis from '../../dispatcher';
import { sanitizedHtmlNode } from '../../HtmlUtils';
import { _t } from '../../languageHandler';
import AccessibleButton from '../views/elements/AccessibleButton';
+import Modal from '../../Modal';
+import classnames from 'classnames';
const RoomSummaryType = PropTypes.shape({
room_id: PropTypes.string.isRequired,
@@ -179,10 +181,13 @@ export default React.createClass({
summary: null,
error: null,
editing: false,
+ saving: false,
+ uploadingAvatar: false,
};
},
componentWillMount: function() {
+ this._changeAvatarComponent = null;
this._loadGroupFromServer(this.props.groupId);
},
@@ -211,8 +216,83 @@ export default React.createClass({
});
},
- _onSettingsClick: function() {
- this.setState({editing: true});
+ _onEditClick: function() {
+ this.setState({
+ editing: true,
+ profileForm: Object.assign({}, this.state.summary.profile),
+ });
+ },
+
+ _onCancelClick: function() {
+ this.setState({
+ editing: false,
+ profileForm: null,
+ });
+ },
+
+ _onNameChange: function(e) {
+ const newProfileForm = Object.assign(this.state.profileForm, { name: e.target.value });
+ this.setState({
+ profileForm: newProfileForm,
+ });
+ },
+
+ _onShortDescChange: function(e) {
+ const newProfileForm = Object.assign(this.state.profileForm, { short_description: e.target.value });
+ this.setState({
+ profileForm: newProfileForm,
+ });
+ },
+
+ _onLongDescChange: function(e) {
+ const newProfileForm = Object.assign(this.state.profileForm, { long_description: e.target.value });
+ this.setState({
+ profileForm: newProfileForm,
+ });
+ },
+
+ _onAvatarSelected: function(ev) {
+ const file = ev.target.files[0];
+ if (!file) return;
+
+ this.setState({uploadingAvatar: true});
+ MatrixClientPeg.get().uploadContent(file).then((url) => {
+ const newProfileForm = Object.assign(this.state.profileForm, { avatar_url: url });
+ this.setState({
+ uploadingAvatar: false,
+ profileForm: newProfileForm,
+ });
+ }).catch((e) => {
+ this.setState({uploadingAvatar: false});
+ const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
+ console.error("Failed to upload avatar image", e);
+ Modal.createDialog(ErrorDialog, {
+ title: _t('Error'),
+ description: _t('Failed to upload image'),
+ });
+ }).done();
+ },
+
+ _onSaveClick: function() {
+ this.setState({saving: true});
+ MatrixClientPeg.get().setGroupProfile(this.props.groupId, this.state.profileForm).then((result) => {
+ this.setState({
+ saving: false,
+ editing: false,
+ summary: null,
+ });
+ this._loadGroupFromServer(this.props.groupId);
+ }).catch((e) => {
+ this.setState({
+ saving: false,
+ });
+ const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
+ console.error("Failed to save group profile", e);
+ Modal.createDialog(ErrorDialog, {
+ title: _t('Error'),
+ description: _t('Failed to update group'),
+ });
+ }).done();
},
_getFeaturedRoomsNode() {
@@ -296,60 +376,129 @@ export default React.createClass({
const Loader = sdk.getComponent("elements.Spinner");
const TintableSvg = sdk.getComponent("elements.TintableSvg");
- if (this.state.summary === null && this.state.error === null) {
+ if (this.state.summary === null && this.state.error === null || this.state.saving) {
return