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

125 lines
3.2 KiB
JavaScript
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
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'
import PageTitle from '../features/ui/util/page_title'
import Text from '../components/text'
2020-02-24 21:56:07 +00:00
import DefaultLayout from '../layouts/default_layout'
import GroupsCollection from '../features/groups_collection'
import WrappedBundle from '../features/ui/util/wrapped_bundle'
import { openModal } from '../actions/modal'
import { MODAL_PRO_UPGRADE } from '../constants'
import {
GroupsPanel,
LinkFooter,
} from '../features/ui/util/async_components'
2020-02-22 23:26:23 +00:00
class GroupsPage extends React.PureComponent {
2020-03-25 03:08:43 +00:00
handleOpenProUpgradeModal = () => {
this.props.dispatch(openModal(MODAL_PRO_UPGRADE))
}
2020-02-22 23:26:23 +00:00
render() {
2020-04-11 23:29:19 +01:00
const {
activeTab,
2020-04-11 23:29:19 +01:00
intl,
children,
isPro,
} = this.props
2020-02-22 23:26:23 +00:00
const dontShowChildren = (activeTab === 'timeline' && !me)
const tabs = !!me ? [
2020-02-22 23:26:23 +00:00
{
title: intl.formatMessage(messages.myGroupsTimeline),
2020-04-08 02:06:59 +01:00
to: '/groups',
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
},
{
title: intl.formatMessage(messages.featured),
to: '/groups/browse/featured',
},
{
title: intl.formatMessage(messages.new),
to: '/groups/browse/new',
},
{
title: intl.formatMessage(messages.categories),
to: '/groups/browse/categories',
},
] : []
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)
const layout = []
if (!!me) {
layout.push(<WrappedBundle component={GroupsPanel} componentParams={{ groupType: 'member' }} />)
}
layout.push(LinkFooter)
2020-04-11 23:29:19 +01:00
2020-02-22 23:26:23 +00:00
return (
<DefaultLayout
noSearch
2020-04-11 23:29:19 +01:00
title={title}
actions={[
{
title: 'Create',
icon: 'add',
to: isPro ? '/groups/create' : undefined,
onClick: isPro ? undefined : this.handleOpenProUpgradeModal,
},
]}
2020-04-28 06:33:58 +01:00
tabs={tabs}
page='groups'
layout={layout}
2020-02-22 23:26:23 +00:00
>
2020-04-11 23:29:19 +01:00
<PageTitle path={title} />
{
!dontShowChildren && children
}
{
dontShowChildren &&
<GroupsCollection activeTab='featured' />
}
2020-02-22 23:26:23 +00:00
</DefaultLayout>
)
}
2020-04-08 02:06:59 +01:00
}
const messages = defineMessages({
groups: { id: 'groups', defaultMessage: 'Groups' },
new: { id: 'new', defaultMessage: 'Recently Added Groups' },
featured: { id: 'featured', defaultMessage: 'Featured Groups' },
myGroupsTimeline: { id: 'my_groups_timeline', defaultMessage: 'Timeline' },
myGroups: { id: 'my_groups', defaultMessage: 'My Groups' },
categories: { id: 'categories', defaultMessage: 'Categories' },
admin: { id: 'admin', defaultMessage: 'Admin' },
})
const mapStateToProps = (state) => ({
isPro: state.getIn(['accounts', me, 'is_pro']),
})
GroupsPage.propTypes = {
activeTab: PropTypes.string.isRequired,
intl: PropTypes.object.isRequired,
children: PropTypes.node.isRequired,
isPro: PropTypes.bool,
}
export default injectIntl(connect(mapStateToProps)(GroupsPage))