From f2afd852d85fb07b9b5337c62dcb2ebd1b9e4a91 Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 21 Jul 2017 14:03:10 +0100 Subject: [PATCH] Make group editing work --- src/components/structures/GroupView.js | 50 +++++++++++++++++--------- src/i18n/strings/en_EN.json | 4 ++- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/components/structures/GroupView.js b/src/components/structures/GroupView.js index b0194fda9a..e6dac09940 100644 --- a/src/components/structures/GroupView.js +++ b/src/components/structures/GroupView.js @@ -22,6 +22,7 @@ import dis from '../../dispatcher'; import { sanitizedHtmlNode } from '../../HtmlUtils'; import { _t } from '../../languageHandler'; import AccessibleButton from '../views/elements/AccessibleButton'; +import Modal from '../../Modal'; const RoomSummaryType = PropTypes.shape({ room_id: PropTypes.string.isRequired, @@ -180,6 +181,7 @@ export default React.createClass({ error: null, editing: false, saving: false, + uploadingAvatar: false, }; }, @@ -199,10 +201,6 @@ export default React.createClass({ } }, - _collectChangeAvatar: function(node) { - this._changeAvatarComponent = node; - }, - _loadGroupFromServer: function(groupId) { MatrixClientPeg.get().getGroupSummary(groupId).done((res) => { this.setState({ @@ -252,14 +250,26 @@ export default React.createClass({ }); }, - _onAvatarSelected: function(e) { - }, + _onAvatarSelected: function(ev) { + const file = ev.target.files[0]; + if (!file) return; - _onAvatarChange: function(newAvatarUrl) { - const newProfileForm = Object.assign(this.state.profileForm, { avatar_url: newAvatarUrl }); - this.setState({ - profileForm: newProfileForm, - }); + 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() { @@ -378,15 +388,21 @@ export default React.createClass({ let headerBottom; let roomBody; if (this.state.editing) { + let avatarImage; + if (this.state.uploadingAvatar) { + avatarImage = ; + } else { + const GroupAvatar = sdk.getComponent('avatars.GroupAvatar'); + avatarImage = ; + } + avatarNode = (