2019-07-02 03:10:25 -04:00
import ImmutablePropTypes from 'react-immutable-proptypes' ;
2019-08-13 11:54:29 -04:00
import ImmutablePureComponent from 'react-immutable-pure-component' ;
2019-08-07 01:02:36 -04:00
import StatusListContainer from '../../../containers/status_list_container' ;
2019-07-02 03:10:25 -04:00
import { FormattedMessage , injectIntl } from 'react-intl' ;
import { connectGroupStream } from '../../../actions/streaming' ;
import { expandGroupTimeline } from '../../../actions/timelines' ;
2019-08-07 01:02:36 -04:00
import ColumnIndicator from '../../../components/column_indicator' ;
2019-08-13 11:54:29 -04:00
import TimelineComposeBlock from '../../../components/timeline_compose_block' ;
2019-07-02 03:10:25 -04:00
const mapStateToProps = ( state , props ) => ( {
2019-08-07 01:02:36 -04:00
group : state . getIn ( [ 'groups' , props . params . id ] ) ,
relationships : state . getIn ( [ 'group_relationships' , props . params . id ] ) ,
hasUnread : state . getIn ( [ 'timelines' , ` group: ${ props . params . id } ` , 'unread' ] ) > 0 ,
2019-07-02 03:10:25 -04:00
} ) ;
export default @ connect ( mapStateToProps )
@ injectIntl
2019-08-13 11:54:29 -04:00
class GroupTimeline extends ImmutablePureComponent {
2019-08-07 01:02:36 -04:00
2019-07-15 16:47:05 +03:00
static contextTypes = {
2019-08-07 01:02:36 -04:00
router : PropTypes . object ,
2019-07-15 16:47:05 +03:00
} ;
2019-07-02 03:10:25 -04:00
2019-07-15 16:47:05 +03:00
static propTypes = {
2019-08-07 01:02:36 -04:00
params : PropTypes . object . isRequired ,
dispatch : PropTypes . func . isRequired ,
columnId : PropTypes . string ,
hasUnread : PropTypes . bool ,
group : PropTypes . oneOfType ( [ ImmutablePropTypes . map , PropTypes . bool ] ) ,
relationships : ImmutablePropTypes . map ,
intl : PropTypes . object . isRequired ,
2019-07-15 16:47:05 +03:00
} ;
2019-07-02 03:10:25 -04:00
2019-07-15 16:47:05 +03:00
componentDidMount ( ) {
2019-08-07 01:02:36 -04:00
const { dispatch } = this . props ;
const { id } = this . props . params ;
2019-07-02 03:10:25 -04:00
2019-08-07 01:02:36 -04:00
dispatch ( expandGroupTimeline ( id ) ) ;
2019-07-02 03:10:25 -04:00
2019-08-07 01:02:36 -04:00
this . disconnect = dispatch ( connectGroupStream ( id ) ) ;
2019-07-15 16:47:05 +03:00
}
2019-07-02 03:10:25 -04:00
2019-07-15 16:47:05 +03:00
componentWillUnmount ( ) {
2019-08-07 01:02:36 -04:00
if ( this . disconnect ) {
this . disconnect ( ) ;
this . disconnect = null ;
}
2019-07-15 16:47:05 +03:00
}
2019-07-02 03:10:25 -04:00
2019-07-15 16:47:05 +03:00
handleLoadMore = maxId => {
2019-08-07 01:02:36 -04:00
const { id } = this . props . params ;
this . props . dispatch ( expandGroupTimeline ( id , { maxId } ) ) ;
2019-07-15 16:47:05 +03:00
}
2019-07-02 03:10:25 -04:00
2019-07-15 16:47:05 +03:00
render ( ) {
2019-08-13 11:54:29 -04:00
const { columnId , group , relationships } = this . props ;
2019-08-07 01:02:36 -04:00
const { id } = this . props . params ;
2019-07-02 03:10:25 -04:00
2019-08-07 01:02:36 -04:00
if ( typeof group === 'undefined' || ! relationships ) {
return ( < ColumnIndicator type = 'loading' / > ) ;
} else if ( group === false ) {
return ( < ColumnIndicator type = 'missing' / > ) ;
}
2019-07-02 03:10:25 -04:00
2019-08-07 01:02:36 -04:00
return (
2019-08-13 11:54:29 -04:00
< div >
{
relationships . get ( 'member' ) &&
< TimelineComposeBlock size = { 46 } group = { group } shouldCondense = { true } autoFocus = { false } / >
}
2019-07-02 03:10:25 -04:00
2019-08-13 11:54:29 -04:00
< div className = 'group__feed' >
2019-08-07 01:02:36 -04:00
< StatusListContainer
scrollKey = { ` group_timeline- ${ columnId } ` }
timelineId = { ` group: ${ id } ` }
onLoadMore = { this . handleLoadMore }
group = { group }
withGroupAdmin = { relationships && relationships . get ( 'admin' ) }
emptyMessage = { < FormattedMessage id = 'empty_column.group' defaultMessage = 'There is nothing in this group yet. When members of this group post new statuses, they will appear here.' / > }
2019-08-13 11:54:29 -04:00
/ >
2019-08-07 01:02:36 -04:00
< / d i v >
< / d i v >
) ;
2019-07-15 16:47:05 +03:00
}
2019-08-07 01:02:36 -04:00
2019-07-15 19:08:36 +03:00
}