From 571fada77ed39c7c67a1bf03ceb49b763657f81f Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 21 Jul 2017 11:12:15 +0100 Subject: [PATCH] Make group profile editing mostly work apart from avatars --- src/components/structures/GroupView.js | 51 ++++++++++++++++--- src/components/views/settings/ChangeAvatar.js | 16 +++--- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/src/components/structures/GroupView.js b/src/components/structures/GroupView.js index d902309571..b0194fda9a 100644 --- a/src/components/structures/GroupView.js +++ b/src/components/structures/GroupView.js @@ -179,10 +179,12 @@ export default React.createClass({ summary: null, error: null, editing: false, + saving: false, }; }, componentWillMount: function() { + this._changeAvatarComponent = null; this._loadGroupFromServer(this.props.groupId); }, @@ -197,6 +199,10 @@ export default React.createClass({ } }, + _collectChangeAvatar: function(node) { + this._changeAvatarComponent = node; + }, + _loadGroupFromServer: function(groupId) { MatrixClientPeg.get().getGroupSummary(groupId).done((res) => { this.setState({ @@ -246,8 +252,36 @@ export default React.createClass({ }); }, + _onAvatarSelected: function(e) { + }, + + _onAvatarChange: function(newAvatarUrl) { + const newProfileForm = Object.assign(this.state.profileForm, { avatar_url: newAvatarUrl }); + this.setState({ + profileForm: newProfileForm, + }); + }, + _onSaveClick: function() { - // TODO: There's no API to edit group profile info yet. + this.setState({saving: true}); + MatrixClientPeg.get().setGroupProfile(this.props.groupId, this.state.profileForm).then((result) => { + this.setState({ + saving: false, + editing: false, + summary: false, + }); + return 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() { @@ -330,8 +364,9 @@ export default React.createClass({ const GroupAvatar = sdk.getComponent("avatars.GroupAvatar"); const Loader = sdk.getComponent("elements.Spinner"); const ChangeAvatar = sdk.getComponent("settings.ChangeAvatar"); + 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 ; } else if (this.state.summary) { const summary = this.state.summary; @@ -345,16 +380,16 @@ export default React.createClass({ if (this.state.editing) { avatarNode = (
-
+
+
-
; // disabled until editing works - rightButtons = null;/* + rightButtons = - ;*/ + ; } return ( diff --git a/src/components/views/settings/ChangeAvatar.js b/src/components/views/settings/ChangeAvatar.js index a5e995e7c6..8c84f592be 100644 --- a/src/components/views/settings/ChangeAvatar.js +++ b/src/components/views/settings/ChangeAvatar.js @@ -33,12 +33,10 @@ module.exports = React.createClass({ height: React.PropTypes.number, className: React.PropTypes.string, - // If true, set the room / user avatar once the image is uploaded. - // Ignored for groups. - setAvatar: React.PropTypes.bool, - - // Called after the avatar is uploaded - onAvatar: React.PropTypes.func, + // Called with the mxc URL of the uploaded image after the avatar is + // uploaded. If undefined, the room or user avatar if changed once the + // image has finished uploading. Must be set for groups. + onUploadComplete: React.PropTypes.func, }, Phases: { @@ -53,7 +51,6 @@ module.exports = React.createClass({ className: "", width: 80, height: 80, - setAvatar: true, }; }, @@ -85,8 +82,7 @@ module.exports = React.createClass({ newUrl = url; if (this.props.onAvatar) { this.props.onAvatar(url); - } - if (this.props.setAvatar) { + } else { if (self.props.room) { return MatrixClientPeg.get().sendStateEvent( self.props.room.roomId, @@ -94,7 +90,7 @@ module.exports = React.createClass({ {url: url}, '' ); - } else { + } else if (!this.props.groupId) { return MatrixClientPeg.get().setAvatarUrl(url); } }