gab-social/app/javascript/gabsocial/features/groups/index/index.js

89 lines
2.9 KiB
JavaScript
Raw Normal View History

2019-07-02 08:10:25 +01:00
import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { fetchGroups } from '../../../actions/groups';
2019-07-15 14:47:05 +01:00
import { defineMessages, injectIntl } from 'react-intl';
2019-07-02 08:10:25 +01:00
import ImmutablePureComponent from 'react-immutable-pure-component';
2019-07-15 14:47:05 +01:00
import { Link } from 'react-router-dom';
import classNames from 'classnames';
import GroupCard from './card';
2019-07-18 20:37:53 +01:00
import GroupCreate from '../create';
2019-07-02 08:10:25 +01:00
const messages = defineMessages({
2019-07-15 14:47:05 +01:00
heading: { id: 'column.groups', defaultMessage: 'Groups' },
2019-07-17 19:22:19 +01:00
create: { id: 'groups.create', defaultMessage: 'Create group' },
tab_featured: { id: 'groups.tab_featured', defaultMessage: 'Featured' },
tab_member: { id: 'groups.tab_member', defaultMessage: 'Groups you\'re in' },
tab_admin: { id: 'groups.tab_admin', defaultMessage: 'Groups you manage' },
2019-07-02 08:10:25 +01:00
});
2019-07-15 14:47:05 +01:00
const mapStateToProps = (state, { activeTab }) => ({
groupIds: state.getIn(['group_lists', activeTab]),
2019-07-02 08:10:25 +01:00
});
export default @connect(mapStateToProps)
@injectIntl
class Groups extends ImmutablePureComponent {
2019-07-15 14:47:05 +01:00
static propTypes = {
params: PropTypes.object.isRequired,
activeTab: PropTypes.string.isRequired,
2019-07-18 20:37:53 +01:00
showCreateForm: PropTypes.bool,
2019-07-15 14:47:05 +01:00
dispatch: PropTypes.func.isRequired,
groups: ImmutablePropTypes.map,
groupIds: ImmutablePropTypes.list,
intl: PropTypes.object.isRequired,
};
2019-07-02 08:10:25 +01:00
2019-07-15 14:47:05 +01:00
componentWillMount () {
this.props.dispatch(fetchGroups(this.props.activeTab));
}
2019-07-02 08:10:25 +01:00
2019-07-15 14:47:05 +01:00
componentDidUpdate(oldProps) {
if (this.props.activeTab && this.props.activeTab !== oldProps.activeTab) {
this.props.dispatch(fetchGroups(this.props.activeTab));
}
}
2019-07-02 08:10:25 +01:00
2019-07-18 20:37:53 +01:00
renderHeader() {
const { intl, activeTab } = this.props;
2019-07-02 08:10:25 +01:00
2019-07-18 20:37:53 +01:00
return (
<div className="group-column-header">
<div className="group-column-header__cta"><Link to="/groups/create" className="button standard-small">{intl.formatMessage(messages.create)}</Link></div>
2019-07-18 20:37:53 +01:00
<div className="group-column-header__title">{intl.formatMessage(messages.heading)}</div>
2019-07-02 08:10:25 +01:00
2019-07-18 20:37:53 +01:00
<div className="column-header__wrapper">
<h1 className="column-header">
<Link to='/groups' className={classNames('btn grouped', {'active': 'featured' === activeTab})}>
{intl.formatMessage(messages.tab_featured)}
</Link>
2019-07-02 08:10:25 +01:00
2019-07-18 20:37:53 +01:00
<Link to='/groups/browse/member' className={classNames('btn grouped', {'active': 'member' === activeTab})}>
{intl.formatMessage(messages.tab_member)}
</Link>
2019-07-02 08:10:25 +01:00
2019-07-18 20:37:53 +01:00
<Link to='/groups/browse/admin' className={classNames('btn grouped', {'active': 'admin' === activeTab})}>
{intl.formatMessage(messages.tab_admin)}
</Link>
</h1>
</div>
</div>
);
}
2019-07-02 08:10:25 +01:00
2019-07-15 14:47:05 +01:00
render () {
2019-07-18 20:37:53 +01:00
const { groupIds, showCreateForm } = this.props;
2019-07-02 08:10:25 +01:00
2019-07-15 14:47:05 +01:00
return (
<div>
2019-07-18 20:37:53 +01:00
{!showCreateForm && this.renderHeader()}
{showCreateForm && <GroupCreate /> }
2019-07-02 08:10:25 +01:00
2019-07-15 14:47:05 +01:00
<div className="group-card-list">
{groupIds.map(id => <GroupCard key={id} id={id} />)}
</div>
</div>
);
}
}