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

108 lines
2.7 KiB
JavaScript
Raw Normal View History

import { Fragment } from 'react'
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'
2020-02-22 23:26:23 +00:00
import LinkFooter from '../components/link_footer'
import Text from '../components/text'
2020-02-22 23:26:23 +00:00
import GroupsPanel from '../components/panel/groups_panel'
2020-02-24 21:56:07 +00:00
import DefaultLayout from '../layouts/default_layout'
import GroupsCollection from '../features/groups_collection'
2020-02-22 23:26:23 +00:00
2020-04-11 23:29:19 +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' },
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
export default
2020-04-11 23:29:19 +01:00
@injectIntl
@connect(mapStateToProps)
2020-03-25 03:08:43 +00:00
class GroupsPage extends PureComponent {
static propTypes = {
activeTab: PropTypes.string.isRequired,
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-05-07 05:03:34 +01:00
}
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 actions = isPro ? [
2020-05-07 05:03:34 +01:00
{
icon: 'add',
to: '/groups/create',
2020-05-07 05:03:34 +01:00
},
] : []
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',
},
] : []
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(<GroupsPanel key='groups-page-groups-panel' groupType='member' />)
}
layout.push(<LinkFooter key='groups-page-link-footer' />)
2020-04-11 23:29:19 +01:00
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={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
}