2017-06-29 19:03:05 +03:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
2019-08-05 14:26:31 +03:00
|
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
2020-07-10 21:07:11 +03:00
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2017-06-29 19:03:05 +03:00
|
|
|
|
|
|
|
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';
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as sdk from '../../index';
|
2017-11-13 22:19:33 +03:00
|
|
|
import { _t } from '../../languageHandler';
|
2020-07-10 21:07:11 +03:00
|
|
|
import SdkConfig from '../../SdkConfig';
|
2020-05-14 05:41:41 +03:00
|
|
|
import dis from '../../dispatcher/dispatcher';
|
2017-06-29 19:03:05 +03:00
|
|
|
import AccessibleButton from '../views/elements/AccessibleButton';
|
2019-12-17 20:26:12 +03:00
|
|
|
import MatrixClientContext from "../../contexts/MatrixClientContext";
|
2020-03-17 16:28:07 +03:00
|
|
|
import AutoHideScrollbar from "./AutoHideScrollbar";
|
2021-06-29 15:11:58 +03:00
|
|
|
import { replaceableComponent } from "../../utils/replaceableComponent";
|
2021-04-27 18:29:42 +03:00
|
|
|
import BetaCard from "../views/beta/BetaCard";
|
2017-06-29 19:03:05 +03:00
|
|
|
|
2021-03-09 05:35:10 +03:00
|
|
|
@replaceableComponent("structures.MyGroups")
|
2020-08-29 14:14:16 +03:00
|
|
|
export default class MyGroups extends React.Component {
|
|
|
|
static contextType = MatrixClientContext;
|
2017-06-29 19:03:05 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
state = {
|
|
|
|
groups: null,
|
|
|
|
error: null,
|
|
|
|
};
|
2017-06-29 19:03:05 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
componentDidMount() {
|
2017-06-29 19:03:05 +03:00
|
|
|
this._fetch();
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2017-06-29 19:03:05 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
_onCreateGroupClick = () => {
|
2021-06-29 15:11:58 +03:00
|
|
|
dis.dispatch({ action: 'view_create_group' });
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2017-06-29 19:03:05 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
_fetch() {
|
2019-12-17 20:26:12 +03:00
|
|
|
this.context.getJoinedGroups().then((result) => {
|
2021-06-29 15:11:58 +03:00
|
|
|
this.setState({ groups: result.groups, error: null });
|
2017-06-29 19:03:05 +03:00
|
|
|
}, (err) => {
|
2017-11-28 15:08:53 +03:00
|
|
|
if (err.errcode === 'M_GUEST_ACCESS_FORBIDDEN') {
|
|
|
|
// Indicate that the guest isn't in any groups (which should be true)
|
2021-06-29 15:11:58 +03:00
|
|
|
this.setState({ groups: [], error: null });
|
2017-11-28 15:08:53 +03:00
|
|
|
return;
|
|
|
|
}
|
2021-06-29 15:11:58 +03:00
|
|
|
this.setState({ groups: null, error: err });
|
2017-06-29 19:03:05 +03:00
|
|
|
});
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2017-06-29 19:03:05 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
render() {
|
2020-07-10 21:07:11 +03:00
|
|
|
const brand = SdkConfig.get().brand;
|
2017-06-29 19:03:05 +03:00
|
|
|
const Loader = sdk.getComponent("elements.Spinner");
|
|
|
|
const SimpleRoomHeader = sdk.getComponent('rooms.SimpleRoomHeader');
|
2017-11-21 14:50:41 +03:00
|
|
|
const GroupTile = sdk.getComponent("groups.GroupTile");
|
2017-06-29 19:03:05 +03:00
|
|
|
|
|
|
|
let content;
|
2017-11-03 14:19:29 +03:00
|
|
|
let contentHeader;
|
2017-06-29 19:03:05 +03:00
|
|
|
if (this.state.groups) {
|
2017-07-07 12:41:59 +03:00
|
|
|
const groupNodes = [];
|
2017-06-29 19:03:05 +03:00
|
|
|
this.state.groups.forEach((g) => {
|
2018-06-15 20:55:37 +03:00
|
|
|
groupNodes.push(<GroupTile key={g} groupId={g} />);
|
2017-06-29 19:03:05 +03:00
|
|
|
});
|
2017-11-03 14:19:29 +03:00
|
|
|
contentHeader = groupNodes.length > 0 ? <h3>{ _t('Your Communities') }</h3> : <div />;
|
2017-10-20 19:28:33 +03:00
|
|
|
content = groupNodes.length > 0 ?
|
2020-03-17 16:28:07 +03:00
|
|
|
<AutoHideScrollbar className="mx_MyGroups_scrollable">
|
2018-02-27 12:20:06 +03:00
|
|
|
<div className="mx_MyGroups_microcopy">
|
|
|
|
<p>
|
|
|
|
{ _t(
|
2020-07-10 21:07:11 +03:00
|
|
|
"Did you know: you can use communities to filter your %(brand)s experience!",
|
|
|
|
{ brand },
|
2018-02-27 12:20:06 +03:00
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
{ _t(
|
2021-06-02 13:33:25 +03:00
|
|
|
"You can click on an avatar in the " +
|
2018-02-27 12:20:06 +03:00
|
|
|
"filter panel at any time to see only the rooms and people associated " +
|
|
|
|
"with that community.",
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
</div>
|
2018-02-14 20:53:54 +03:00
|
|
|
<div className="mx_MyGroups_joinedGroups">
|
|
|
|
{ groupNodes }
|
|
|
|
</div>
|
2020-03-17 16:28:07 +03:00
|
|
|
</AutoHideScrollbar> :
|
2017-10-20 19:28:33 +03:00
|
|
|
<div className="mx_MyGroups_placeholder">
|
|
|
|
{ _t(
|
2017-10-20 20:10:14 +03:00
|
|
|
"You're not currently a member of any communities.",
|
2017-10-20 19:28:33 +03:00
|
|
|
) }
|
|
|
|
</div>;
|
2017-06-29 19:03:05 +03:00
|
|
|
} else if (this.state.error) {
|
|
|
|
content = <div className="mx_MyGroups_error">
|
2017-10-16 15:18:39 +03:00
|
|
|
{ _t('Error whilst fetching joined communities') }
|
2017-06-29 19:03:05 +03:00
|
|
|
</div>;
|
2017-06-29 20:30:16 +03:00
|
|
|
} else {
|
|
|
|
content = <Loader />;
|
2017-06-29 19:03:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return <div className="mx_MyGroups">
|
2019-01-11 04:37:28 +03:00
|
|
|
<SimpleRoomHeader title={_t("Communities")} icon={require("../../../res/img/icons-groups.svg")} />
|
2017-10-20 19:28:33 +03:00
|
|
|
<div className='mx_MyGroups_header'>
|
|
|
|
<div className="mx_MyGroups_headerCard">
|
|
|
|
<AccessibleButton className='mx_MyGroups_headerCard_button' onClick={this._onCreateGroupClick}>
|
2017-06-30 15:59:49 +03:00
|
|
|
</AccessibleButton>
|
2017-10-20 19:28:33 +03:00
|
|
|
<div className="mx_MyGroups_headerCard_content">
|
|
|
|
<div className="mx_MyGroups_headerCard_header">
|
|
|
|
{ _t('Create a new community') }
|
|
|
|
</div>
|
|
|
|
{ _t(
|
|
|
|
'Create a community to group together users and rooms! ' +
|
|
|
|
'Build a custom homepage to mark out your space in the Matrix universe.',
|
|
|
|
) }
|
2017-06-30 15:59:49 +03:00
|
|
|
</div>
|
2017-10-20 19:28:33 +03:00
|
|
|
</div>
|
2021-07-20 00:43:11 +03:00
|
|
|
{ /*<div className="mx_MyGroups_joinBox mx_MyGroups_headerCard">
|
2017-10-20 19:28:33 +03:00
|
|
|
<AccessibleButton className='mx_MyGroups_headerCard_button' onClick={this._onJoinGroupClick}>
|
2021-06-28 18:30:48 +03:00
|
|
|
<img src={require("../../../res/img/icons-create-room.svg")} width="50" height="50" />
|
2017-06-30 15:59:49 +03:00
|
|
|
</AccessibleButton>
|
2017-10-20 19:28:33 +03:00
|
|
|
<div className="mx_MyGroups_headerCard_content">
|
|
|
|
<div className="mx_MyGroups_headerCard_header">
|
|
|
|
{ _t('Join an existing community') }
|
|
|
|
</div>
|
2017-11-13 22:19:33 +03:00
|
|
|
{ _t(
|
2017-10-20 19:28:33 +03:00
|
|
|
'To join an existing community you\'ll have to '+
|
|
|
|
'know its community identifier; this will look '+
|
|
|
|
'something like <i>+example:matrix.org</i>.',
|
2017-11-13 22:19:33 +03:00
|
|
|
{},
|
|
|
|
{ 'i': (sub) => <i>{ sub }</i> })
|
|
|
|
}
|
2017-10-20 19:28:33 +03:00
|
|
|
</div>
|
2021-07-20 00:43:11 +03:00
|
|
|
</div>*/ }
|
2017-06-30 15:59:49 +03:00
|
|
|
</div>
|
2021-04-29 18:08:59 +03:00
|
|
|
<BetaCard featureId="feature_spaces" title={_t("Communities are changing to Spaces")} />
|
2017-06-30 15:59:49 +03:00
|
|
|
<div className="mx_MyGroups_content">
|
2017-11-03 14:19:29 +03:00
|
|
|
{ contentHeader }
|
2017-09-28 13:21:06 +03:00
|
|
|
{ content }
|
2017-06-29 19:03:05 +03:00
|
|
|
</div>
|
|
|
|
</div>;
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
|
|
|
}
|