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

90 lines
2.5 KiB
JavaScript
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
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-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 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() {
this.props.dispatch(fetchGroup(this.props.params.id))
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
const isPrivate = !!group ? group.get('is_private') : false
const isMember = !!relationships ? relationships.get('member') : false
const unavailable = isPrivate && !isMember
2019-07-15 14:47:05 +01:00
return (
2020-02-28 15:20:47 +00:00
<GroupLayout
title={'Group'}
2020-02-29 15:42:47 +00:00
group={group}
groupId={groupId}
2020-02-29 15:42:47 +00:00
relationships={relationships}
>
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 && isMember &&
<React.Fragment>
<TimelineComposeBlock size={46} groupId={groupId} autoFocus />
2020-02-28 15:20:47 +00:00
<Divider />
</React.Fragment>
2020-02-28 15:20:47 +00:00
}
2020-04-11 23:29:19 +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
)
}
}
const messages = defineMessages({
group: { id: 'group', defaultMessage: 'Group' },
groupPrivate: { id: 'group_private', defaultMessage: 'This group is private. You must request to join in order to view this group.' },
})
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))