gab-social/app/javascript/gabsocial/pages/groups_page.js

108 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-04-02 04:17:21 +01:00
import { me } from '../initial_state'
2020-04-11 23:29:19 +01:00
import { defineMessages, injectIntl } from 'react-intl'
2020-03-25 03:08:43 +00:00
import { openModal } from '../actions/modal'
2020-05-07 05:03:34 +01:00
import {
MODAL_GROUP_CREATE,
MODAL_PRO_UPGRADE,
} from '../constants'
2020-04-11 23:29:19 +01:00
import PageTitle from '../features/ui/util/page_title'
2020-02-22 23:26:23 +00:00
import LinkFooter from '../components/link_footer'
import GroupsPanel from '../components/panel/groups_panel'
2020-03-25 03:08:43 +00:00
import WhoToFollowPanel from '../components/panel/who_to_follow_panel'
2020-02-24 21:56:07 +00:00
import DefaultLayout from '../layouts/default_layout'
2020-02-22 23:26:23 +00:00
2020-04-11 23:29:19 +01:00
const messages = defineMessages({
groups: { id: 'groups', defaultMessage: 'Groups' },
featured: { id: 'featured', defaultMessage: 'Featured' },
2020-04-29 23:32:49 +01:00
new: { id: 'new', defaultMessage: 'Just Added' },
2020-04-11 23:29:19 +01:00
myGroups: { id: 'my_groups', defaultMessage: 'My Groups' },
admin: { id: 'admin', defaultMessage: 'Admin' },
})
2020-04-02 04:17:21 +01:00
2020-04-11 23:29:19 +01:00
const mapStateToProps = (state) => ({
isPro: state.getIn(['accounts', me, 'is_pro']),
})
2020-03-25 03:08:43 +00:00
2020-04-11 23:29:19 +01:00
const mapDispatchToProps = (dispatch) => ({
2020-05-07 05:03:34 +01:00
onOpenGroupCreateModal(isPro) {
if (!isPro) {
dispatch(openModal(MODAL_PRO_UPGRADE))
} else {
dispatch(openModal(MODAL_GROUP_CREATE))
}
2020-03-25 03:08:43 +00:00
},
})
export default
2020-04-11 23:29:19 +01:00
@injectIntl
2020-04-02 04:17:21 +01:00
@connect(mapStateToProps, mapDispatchToProps)
2020-03-25 03:08:43 +00:00
class GroupsPage extends PureComponent {
static propTypes = {
2020-04-11 23:29:19 +01:00
intl: PropTypes.object.isRequired,
children: PropTypes.node.isRequired,
2020-04-02 04:17:21 +01:00
isPro: PropTypes.bool,
2020-03-25 03:08:43 +00:00
onOpenGroupCreateModal: PropTypes.func.isRequired,
}
2020-02-22 23:26:23 +00:00
2020-05-07 05:03:34 +01:00
handleOnOpenGroupCreateModal = () => {
this.props.onOpenGroupCreateModal(this.props.isPro)
}
2020-02-22 23:26:23 +00:00
render() {
2020-04-11 23:29:19 +01:00
const {
intl,
children,
isPro,
onOpenGroupCreateModal,
} = this.props
2020-02-22 23:26:23 +00:00
2020-05-07 05:03:34 +01:00
const actions = [
{
icon: 'add',
onClick: this.handleOnOpenGroupCreateModal,
},
]
2020-04-08 02:06:59 +01:00
const tabs = [
2020-02-22 23:26:23 +00:00
{
2020-04-29 23:32:49 +01:00
title: intl.formatMessage(messages.featured),
2020-04-08 02:06:59 +01:00
to: '/groups',
2020-02-22 23:26:23 +00:00
},
2020-03-05 15:44:17 +00:00
{
2020-04-11 23:29:19 +01:00
title: intl.formatMessage(messages.new),
2020-04-08 02:06:59 +01:00
to: '/groups/new',
2020-03-05 15:44:17 +00:00
},
2020-02-22 23:26:23 +00:00
{
2020-04-11 23:29:19 +01:00
title: intl.formatMessage(messages.myGroups),
2020-04-08 02:06:59 +01:00
to: '/groups/browse/member',
2020-02-22 23:26:23 +00:00
},
2020-04-02 04:17:21 +01:00
]
if (isPro) {
tabs.push({
2020-04-11 23:29:19 +01:00
title: intl.formatMessage(messages.admin),
2020-04-08 02:06:59 +01:00
to: '/groups/browse/admin',
2020-04-02 04:17:21 +01:00
})
}
2020-02-22 23:26:23 +00:00
2020-04-11 23:29:19 +01:00
const title = intl.formatMessage(messages.groups)
2020-02-22 23:26:23 +00:00
return (
<DefaultLayout
2020-04-11 23:29:19 +01:00
title={title}
2020-04-02 04:17:21 +01:00
actions={actions}
2020-04-28 06:33:58 +01:00
tabs={tabs}
page='groups'
layout={[
<WhoToFollowPanel key='groups-page-wtf-panel' />,
<GroupsPanel slim key='groups-page-groups-panel' />,
<LinkFooter key='groups-page-link-footer' />,
]}
2020-02-22 23:26:23 +00:00
>
2020-04-11 23:29:19 +01:00
<PageTitle path={title} />
2020-02-22 23:26:23 +00:00
{ children }
</DefaultLayout>
)
}
2020-04-08 02:06:59 +01:00
2020-02-22 23:26:23 +00:00
}