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

50 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-07-20 00:36:55 +01:00
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { defineMessages, injectIntl } from 'react-intl';
import { connect } from 'react-redux';
import Item from './item';
import Icon from 'gabsocial/components/icon';
2019-07-20 00:45:14 +01:00
import { Link } from 'react-router-dom';
2019-07-20 00:36:55 +01:00
const messages = defineMessages({
title: { id: 'groups.sidebar-panel.title', defaultMessage: 'Groups You\'re In' },
2019-07-20 00:45:14 +01:00
show_all: { id: 'groups.sidebar-panel.show_all', defaultMessage: 'Show all' },
2019-07-20 00:36:55 +01:00
});
const mapStateToProps = (state, { id }) => ({
groupIds: state.getIn(['group_lists', 'member']),
});
export default @connect(mapStateToProps)
@injectIntl
class GroupSidebarPanel extends ImmutablePureComponent {
static propTypes = {
groupIds: ImmutablePropTypes.list,
}
render() {
const { intl, groupIds } = this.props;
2019-07-20 00:45:14 +01:00
const count = groupIds.count();
2019-07-20 00:36:55 +01:00
// Only when there are groups to show
2019-07-20 00:45:14 +01:00
if (count === 0) return null;
2019-07-20 00:36:55 +01:00
return (
<div className='wtf-panel group-sidebar-panel'>
<div className='wtf-panel-header'>
<Icon id='users' className='wtf-panel-header__icon' />
<span className='wtf-panel-header__label'>{intl.formatMessage(messages.title)}</span>
</div>
2019-07-20 00:36:55 +01:00
<div className='wtf-panel__content'>
<div className="group-sidebar-panel__items">
2019-07-20 00:45:14 +01:00
{groupIds.slice(0, 10).map(groupId => <Item key={groupId} id={groupId} />)}
{count > 10 && <Link className="group-sidebar-panel__items__show-all" to='/groups/browse/member'>{intl.formatMessage(messages.show_all)}</Link>}
2019-07-20 00:36:55 +01:00
</div>
</div>
</div>
);
}
}