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

81 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-02-28 15:20:47 +00:00
import { Fragment } from 'react'
2020-04-11 23:29:19 +01:00
import { defineMessages, injectIntl } from 'react-intl'
2020-02-28 15:20:47 +00:00
import ImmutablePropTypes from 'react-immutable-proptypes'
import ImmutablePureComponent from 'react-immutable-pure-component'
import { fetchGroup } from '../actions/groups'
2020-04-11 23:29:19 +01:00
import PageTitle from '../features/ui/util/page_title'
2020-02-28 15:20:47 +00:00
import GroupLayout from '../layouts/group_layout'
import TimelineComposeBlock from '../components/timeline_compose_block'
import Divider from '../components/divider'
2019-07-15 14:47:05 +01:00
2020-04-11 23:29:19 +01:00
const messages = defineMessages({
group: { id: 'group', defaultMessage: 'Group' },
})
2019-07-15 14:47:05 +01:00
const mapStateToProps = (state, { params: { id } }) => ({
group: state.getIn(['groups', id]),
relationships: state.getIn(['group_relationships', id]),
2020-02-28 15:20:47 +00:00
})
2019-07-15 14:47:05 +01:00
2020-05-09 03:17:19 +01:00
const mapDispatchToProps = (dispatch) => ({
onFetchGroup(groupId) {
dispatch(fetchGroup(groupId))
},
2020-04-11 23:29:19 +01:00
})
2020-02-25 16:04:44 +00:00
export default
2020-04-11 23:29:19 +01:00
@injectIntl
@connect(mapStateToProps, mapDispatchToProps)
2019-07-15 14:47:05 +01:00
class GroupPage extends ImmutablePureComponent {
2020-02-28 15:20:47 +00:00
static propTypes = {
2020-04-11 23:29:19 +01:00
intl: PropTypes.object.isRequired,
2020-02-28 15:20:47 +00:00
group: ImmutablePropTypes.map,
2020-05-07 06:55:24 +01:00
children: PropTypes.node.isRequired,
2019-07-15 14:47:05 +01:00
relationships: ImmutablePropTypes.map,
2020-05-09 03:17:19 +01:00
onFetchGroup: PropTypes.func.isRequired,
sortByValue: PropTypes.string.isRequired,
sortByTopValue: PropTypes.string.isRequired,
2020-03-12 16:09:15 +00:00
}
2020-04-11 23:29:19 +01:00
componentDidMount() {
2020-05-09 03:17:19 +01:00
this.props.onFetchGroup(this.props.params.id)
// this.props.onFetchGroup(this.props.params.slug)
2019-07-15 14:47:05 +01:00
}
2020-02-28 15:20:47 +00:00
render() {
2020-04-11 23:29:19 +01:00
const {
intl,
children,
group,
relationships,
isTimeline,
2020-04-11 23:29:19 +01:00
} = this.props
2020-02-28 15:20:47 +00:00
2020-04-11 23:29:19 +01:00
const groupTitle = !!group ? group.get('title') : ''
const groupId = !!group ? group.get('id') : undefined
2019-07-15 14:47:05 +01:00
return (
2020-02-28 15:20:47 +00:00
<GroupLayout
2020-04-11 23:29:19 +01:00
showBackBtn
title={'Group'}
2020-02-29 15:42:47 +00:00
group={group}
groupId={groupId}
2020-02-29 15:42:47 +00:00
relationships={relationships}
isTimeline={isTimeline}
>
2020-04-11 23:29:19 +01:00
<PageTitle path={[groupTitle, intl.formatMessage(messages.group)]} />
2020-02-28 15:20:47 +00:00
{
!!relationships && isTimeline && relationships.get('member') &&
2020-02-28 15:20:47 +00:00
<Fragment>
<TimelineComposeBlock size={46} groupId={groupId} autoFocus />
2020-02-28 15:20:47 +00:00
<Divider />
</Fragment>
}
2020-04-11 23:29:19 +01:00
{children}
2020-02-28 15:20:47 +00:00
</GroupLayout>
2019-07-15 14:47:05 +01:00
)
}
}