2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-08-17 21:39:25 +01:00
|
|
|
import { connect } from 'react-redux'
|
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-12-24 18:18:54 +00:00
|
|
|
import { changeComposeGroupId } from '../actions/compose'
|
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'
|
2020-09-10 23:07:00 +01:00
|
|
|
import Block from '../components/block'
|
|
|
|
import ColumnIndicator from '../components/column_indicator'
|
2020-02-28 15:20:47 +00:00
|
|
|
import Divider from '../components/divider'
|
2019-07-15 14:47:05 +01:00
|
|
|
|
|
|
|
class GroupPage extends ImmutablePureComponent {
|
|
|
|
|
2020-04-11 23:29:19 +01:00
|
|
|
componentDidMount() {
|
2020-08-14 18:45:59 +01:00
|
|
|
this.props.dispatch(fetchGroup(this.props.params.id))
|
2019-07-15 14:47:05 +01:00
|
|
|
}
|
|
|
|
|
2020-12-24 18:18:54 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
//Reset group composer
|
|
|
|
this.props.dispatch(changeComposeGroupId(null))
|
|
|
|
}
|
|
|
|
|
2020-02-28 15:20:47 +00:00
|
|
|
render() {
|
2020-04-11 23:29:19 +01:00
|
|
|
const {
|
|
|
|
intl,
|
|
|
|
children,
|
|
|
|
group,
|
|
|
|
relationships,
|
2020-08-06 06:13:19 +01:00
|
|
|
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') : ''
|
2020-07-15 00:46:43 +01:00
|
|
|
const groupId = !!group ? group.get('id') : undefined
|
2020-09-10 23:07:00 +01:00
|
|
|
|
|
|
|
const isPrivate = !!group ? group.get('is_private') : false
|
|
|
|
const isMember = !!relationships ? relationships.get('member') : false
|
|
|
|
const unavailable = isPrivate && !isMember
|
|
|
|
|
2020-12-21 18:25:05 +00:00
|
|
|
if (!!group) {
|
|
|
|
if (group.get('archived')) return null
|
|
|
|
}
|
|
|
|
|
2019-07-15 14:47:05 +01:00
|
|
|
return (
|
2020-02-28 15:20:47 +00:00
|
|
|
<GroupLayout
|
2020-08-06 06:13:19 +01:00
|
|
|
title={'Group'}
|
2020-02-29 15:42:47 +00:00
|
|
|
group={group}
|
2020-07-16 05:05:08 +01:00
|
|
|
groupId={groupId}
|
2020-02-29 15:42:47 +00:00
|
|
|
relationships={relationships}
|
2019-08-07 06:02:36 +01:00
|
|
|
>
|
2020-04-11 23:29:19 +01:00
|
|
|
<PageTitle path={[groupTitle, intl.formatMessage(messages.group)]} />
|
2020-09-10 23:07:00 +01:00
|
|
|
|
2020-02-28 15:20:47 +00:00
|
|
|
{
|
2020-09-10 23:07:00 +01:00
|
|
|
!!relationships && isTimeline && isMember &&
|
2020-08-17 21:07:16 +01:00
|
|
|
<React.Fragment>
|
2020-07-15 00:46:43 +01:00
|
|
|
<TimelineComposeBlock size={46} groupId={groupId} autoFocus />
|
2020-02-28 15:20:47 +00:00
|
|
|
<Divider />
|
2020-08-17 21:07:16 +01:00
|
|
|
</React.Fragment>
|
2020-02-28 15:20:47 +00:00
|
|
|
}
|
2020-04-11 23:29:19 +01:00
|
|
|
|
2020-09-10 23:07:00 +01:00
|
|
|
{
|
|
|
|
unavailable &&
|
|
|
|
<Block>
|
|
|
|
<ColumnIndicator type='error' message={intl.formatMessage(messages.groupPrivate)} />
|
|
|
|
</Block>
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
!unavailable && children
|
|
|
|
}
|
2020-02-28 15:20:47 +00:00
|
|
|
</GroupLayout>
|
2019-07-15 14:47:05 +01:00
|
|
|
)
|
|
|
|
}
|
2020-08-14 18:45:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
group: { id: 'group', defaultMessage: 'Group' },
|
2020-09-10 23:07:00 +01:00
|
|
|
groupPrivate: { id: 'group_private', defaultMessage: 'This group is private. You must request to join in order to view this group.' },
|
2020-08-14 18:45:59 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
const mapStateToProps = (state, { params: { id } }) => ({
|
|
|
|
group: state.getIn(['groups', id]),
|
|
|
|
relationships: state.getIn(['group_relationships', id]),
|
|
|
|
})
|
|
|
|
|
|
|
|
GroupPage.propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
group: ImmutablePropTypes.map,
|
|
|
|
children: PropTypes.node.isRequired,
|
|
|
|
relationships: ImmutablePropTypes.map,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
sortByValue: PropTypes.string.isRequired,
|
|
|
|
sortByTopValue: PropTypes.string.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(connect(mapStateToProps)(GroupPage))
|