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