bigbuffet-rw/app/soapbox/features/groups/index/card.js

57 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07: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 { Link } from 'react-router-dom';
import { shortNumberFormat } from '../../../utils/numbers';
import { connect } from 'react-redux';
const messages = defineMessages({
2020-04-14 11:44:40 -07:00
members: { id: 'groups.card.members', defaultMessage: 'Members' },
view: { id: 'groups.card.view', defaultMessage: 'View' },
join: { id: 'groups.card.join', defaultMessage: 'Join' },
role_member: { id: 'groups.card.roles.member', defaultMessage: 'You\'re a member' },
role_admin: { id: 'groups.card.roles.admin', defaultMessage: 'You\'re an admin' },
2020-03-27 13:59:38 -07:00
});
const mapStateToProps = (state, { id }) => ({
2020-04-14 11:44:40 -07:00
group: state.getIn(['groups', id]),
relationships: state.getIn(['group_relationships', id]),
2020-03-27 13:59:38 -07:00
});
export default @connect(mapStateToProps)
@injectIntl
class GroupCard extends ImmutablePureComponent {
2020-04-14 11:44:40 -07:00
2020-03-27 13:59:38 -07:00
static propTypes = {
2020-04-14 11:44:40 -07:00
group: ImmutablePropTypes.map,
relationships: ImmutablePropTypes.map,
2020-03-27 13:59:38 -07:00
}
getRole() {
2020-04-14 11:44:40 -07:00
const { intl, relationships } = this.props;
2020-03-27 13:59:38 -07:00
2020-04-14 11:44:40 -07:00
if (relationships.get('admin')) return intl.formatMessage(messages.role_admin);
if (relationships.get('member')) return intl.formatMessage(messages.role_member);
2020-04-14 13:45:38 -07:00
return null;
2020-03-27 13:59:38 -07:00
}
render() {
2020-04-14 11:44:40 -07:00
const { intl, group } = this.props;
const coverImageUrl = group.get('cover_image_url');
const role = this.getRole();
return (
<Link to={`/groups/${group.get('id')}`} className='group-card'>
<div className='group-card__header'>{coverImageUrl && <img alt='' src={coverImageUrl} />}</div>
<div className='group-card__content'>
<div className='group-card__title'>{group.get('title')}</div>
<div className='group-card__meta'><strong>{shortNumberFormat(group.get('member_count'))}</strong> {intl.formatMessage(messages.members)}{role && <span> · {role}</span>}</div>
<div className='group-card__description'>{group.get('description')}</div>
</div>
</Link>
);
2020-03-27 13:59:38 -07:00
}
2020-04-14 11:44:40 -07:00
2020-04-14 13:45:38 -07:00
}