pleroma/app/soapbox/features/groups/timeline/components/header.js

95 lines
3.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 PropTypes from 'prop-types';
2020-05-28 15:52:07 -07:00
import Button from 'soapbox/components/button';
2020-03-27 13:59:38 -07:00
import ImmutablePureComponent from 'react-immutable-pure-component';
import { defineMessages, injectIntl } from 'react-intl';
import { NavLink } from 'react-router-dom';
import DropdownMenuContainer from '../../../../containers/dropdown_menu_container';
const messages = defineMessages({
2020-04-14 11:44:40 -07:00
join: { id: 'groups.join', defaultMessage: 'Join group' },
leave: { id: 'groups.leave', defaultMessage: 'Leave group' },
removed_accounts: { id: 'groups.removed_accounts', defaultMessage: 'Removed Accounts' },
edit: { id: 'groups.edit', defaultMessage: 'Edit' },
2020-03-27 13:59:38 -07:00
});
export default @injectIntl
class Header extends ImmutablePureComponent {
2020-04-14 11:44:40 -07:00
2020-04-14 13:45:38 -07:00
static propTypes = {
group: ImmutablePropTypes.map,
relationships: ImmutablePropTypes.map,
toggleMembership: PropTypes.func.isRequired,
};
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07:00
static contextTypes = {
router: PropTypes.object,
};
2020-03-27 13:59:38 -07:00
2020-04-14 14:37:17 -07:00
toggle = () => {
const { group, relationships, toggleMembership } = this.props;
toggleMembership(group, relationships);
}
2020-04-14 13:45:38 -07:00
getActionButton() {
2020-04-14 14:37:17 -07:00
const { group, relationships, intl } = this.props;
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07:00
if (!relationships) {
return '';
} else if (!relationships.get('member')) {
2020-04-14 14:37:17 -07:00
return <Button className='logo-button' text={intl.formatMessage(messages.join)} onClick={this.toggle} />;
2020-04-14 13:45:38 -07:00
} else if (relationships.get('member')) {
2020-04-14 14:37:17 -07:00
return <Button className='logo-button' text={intl.formatMessage(messages.leave, { name: group.get('title') })} onClick={this.toggle} />;
2020-04-14 13:45:38 -07:00
}
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07:00
return '';
}
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07:00
getAdminMenu() {
const { group, intl } = this.props;
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07:00
const menu = [
{
text: intl.formatMessage(messages.edit),
to: `/groups/${group.get('id')}/edit`,
icon: require('@tabler/icons/icons/edit.svg'),
},
{
text: intl.formatMessage(messages.removed_accounts),
to: `/groups/${group.get('id')}/removed_accounts`,
icon: require('@tabler/icons/icons/trash.svg'),
destructive: true,
},
2020-04-14 13:45:38 -07:00
];
2020-03-27 13:59:38 -07:00
return <DropdownMenuContainer items={menu} src={require('@tabler/icons/icons/dots-vertical.svg')} direction='right' />;
2020-04-14 13:45:38 -07:00
}
2020-04-14 11:44:40 -07:00
render() {
2020-04-14 13:45:38 -07:00
const { group, relationships } = this.props;
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07:00
if (!group || !relationships) {
return null;
}
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07:00
return (
<div className='group__header-container'>
<div className='group__header'>
<div className='group__cover'>
<img src={group.get('cover_image_url')} alt='' className='parallax' />
</div>
<div className='group__tabs'>
<NavLink exact className='group__tabs__tab' activeClassName='group__tabs__tab--active' to={`/groups/${group.get('id')}`}>Posts</NavLink>
<NavLink exact className='group__tabs__tab' activeClassName='group__tabs__tab--active' to={`/groups/${group.get('id')}/members`}>Members</NavLink>
{this.getActionButton()}
{relationships.get('admin') && this.getAdminMenu()}
</div>
</div>
</div>
);
}
2020-04-14 11:44:40 -07:00
2020-03-27 13:59:38 -07:00
}