From c820836bcc1c95d0fb292f47ecb377e602f5b9ee Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 12 Jun 2018 15:22:45 +0100 Subject: [PATCH 1/5] make RoomTooltip generic and add ContextMenu&Tooltip to GroupInviteTile Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- .../GroupInviteTileContextMenu.js | 87 ++++++++++++++++ .../views/groups/GroupInviteTile.js | 98 +++++++++++++++++-- src/components/views/rooms/RoomList.js | 3 +- src/components/views/rooms/RoomTile.js | 4 +- src/components/views/rooms/RoomTooltip.js | 25 ++--- 5 files changed, 189 insertions(+), 28 deletions(-) create mode 100644 src/components/views/context_menus/GroupInviteTileContextMenu.js diff --git a/src/components/views/context_menus/GroupInviteTileContextMenu.js b/src/components/views/context_menus/GroupInviteTileContextMenu.js new file mode 100644 index 0000000000..844845ea82 --- /dev/null +++ b/src/components/views/context_menus/GroupInviteTileContextMenu.js @@ -0,0 +1,87 @@ +/* +Copyright 2018 Vector Creations 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 classNames from 'classnames'; +import PropTypes from 'prop-types'; +import sdk from '../../../index'; +import { _t, _td } from '../../../languageHandler'; +import Modal from '../../../Modal'; +import {Group} from 'matrix-js-sdk'; +import GroupStore from "../../../stores/GroupStore"; + +export default class GroupInviteTileContextMenu extends React.Component { + static propTypes = { + group: PropTypes.instanceOf(Group).isRequired, + /* callback called when the menu is dismissed */ + onFinished: PropTypes.func, + }; + + constructor(props, context) { + super(props, context); + + this._onClickReject = this._onClickReject.bind(this); + } + + componentWillMount() { + this._unmounted = false; + } + + componentWillUnmount() { + this._unmounted = true; + } + + _onClickReject() { + const QuestionDialog = sdk.getComponent('dialogs.QuestionDialog'); + Modal.createTrackedDialog('Reject community invite', '', QuestionDialog, { + title: _t('Reject invitation'), + description: _t('Are you sure you want to reject the invitation?'), + onFinished: async (shouldLeave) => { + if (!shouldLeave) return; + + // FIXME: controller shouldn't be loading a view :( + const Loader = sdk.getComponent("elements.Spinner"); + const modal = Modal.createDialog(Loader, null, 'mx_Dialog_spinner'); + + try { + await GroupStore.leaveGroup(this.props.group.groupId); + } catch (e) { + console.error(e); + const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); + Modal.createTrackedDialog('Error rejecting invite', '', ErrorDialog, { + title: _t("Error"), + description: _t("Unable to reject invite"), + }); + } + modal.close(); + }, + }); + + // Close the context menu + if (this.props.onFinished) { + this.props.onFinished(); + } + } + + render() { + return