2019-07-02 08:10:25 +01:00
import React from 'react' ;
import { connect } from 'react-redux' ;
import PropTypes from 'prop-types' ;
import ImmutablePropTypes from 'react-immutable-proptypes' ;
import StatusListContainer from '../../ui/containers/status_list_container' ;
import Column from '../../../components/column' ;
2019-08-09 01:41:56 +01:00
import { FormattedMessage , injectIntl , defineMessages } from 'react-intl' ;
2019-07-02 08:10:25 +01:00
import { connectGroupStream } from '../../../actions/streaming' ;
import { expandGroupTimeline } from '../../../actions/timelines' ;
import MissingIndicator from '../../../components/missing_indicator' ;
import LoadingIndicator from '../../../components/loading_indicator' ;
2019-07-15 14:47:05 +01:00
import ComposeFormContainer from '../../../../gabsocial/features/compose/containers/compose_form_container' ;
import { me } from 'gabsocial/initial_state' ;
import Avatar from '../../../components/avatar' ;
2019-08-09 01:41:56 +01:00
import { Link } from 'react-router-dom' ;
import classNames from 'classnames' ;
2019-08-09 03:57:12 +01:00
import ColumnSettingsContainer from "./containers/column_settings_container" ;
import Icon from 'gabsocial/components/icon' ;
2019-08-09 01:41:56 +01:00
const messages = defineMessages ( {
tabLatest : { id : 'group.timeline.tab_latest' , defaultMessage : 'Latest' } ,
2019-08-09 03:57:12 +01:00
show : { id : 'group.timeline.show_settings' , defaultMessage : 'Show settings' } ,
hide : { id : 'group.timeline.hide_settings' , defaultMessage : 'Hide settings' } ,
2019-08-09 01:41:56 +01:00
} ) ;
2019-07-02 08:10:25 +01:00
const mapStateToProps = ( state , props ) => ( {
2019-07-15 14:47:05 +01:00
account : state . getIn ( [ 'accounts' , me ] ) ,
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 08:10:25 +01:00
} ) ;
export default @ connect ( mapStateToProps )
@ injectIntl
class GroupTimeline extends React . PureComponent {
2019-07-15 14:47:05 +01:00
static contextTypes = {
router : PropTypes . object ,
} ;
2019-07-02 08:10:25 +01:00
2019-07-15 14:47:05 +01:00
static propTypes = {
params : PropTypes . object . isRequired ,
dispatch : PropTypes . func . isRequired ,
columnId : PropTypes . string ,
hasUnread : PropTypes . bool ,
group : PropTypes . oneOfType ( [ ImmutablePropTypes . map , PropTypes . bool ] ) ,
relationships : ImmutablePropTypes . map ,
account : ImmutablePropTypes . map ,
intl : PropTypes . object . isRequired ,
} ;
2019-07-02 08:10:25 +01:00
2019-08-09 03:57:12 +01:00
state = {
collapsed : true ,
}
2019-07-15 14:47:05 +01:00
componentDidMount ( ) {
const { dispatch } = this . props ;
const { id } = this . props . params ;
2019-07-02 08:10:25 +01:00
2019-07-15 14:47:05 +01:00
dispatch ( expandGroupTimeline ( id ) ) ;
2019-07-02 08:10:25 +01:00
2019-07-15 14:47:05 +01:00
this . disconnect = dispatch ( connectGroupStream ( id ) ) ;
}
2019-07-02 08:10:25 +01:00
2019-07-15 14:47:05 +01:00
componentWillUnmount ( ) {
if ( this . disconnect ) {
this . disconnect ( ) ;
this . disconnect = null ;
}
}
2019-07-02 08:10:25 +01:00
2019-07-15 14:47:05 +01:00
handleLoadMore = maxId => {
const { id } = this . props . params ;
this . props . dispatch ( expandGroupTimeline ( id , { maxId } ) ) ;
}
2019-07-02 08:10:25 +01:00
2019-08-09 03:57:12 +01:00
handleToggleClick = ( e ) => {
e . stopPropagation ( ) ;
this . setState ( { collapsed : ! this . state . collapsed } ) ;
}
2019-07-15 14:47:05 +01:00
render ( ) {
2019-08-09 01:41:56 +01:00
const { columnId , group , relationships , account , intl } = this . props ;
2019-08-09 03:57:12 +01:00
const { collapsed } = this . state ;
2019-07-15 14:47:05 +01:00
const { id } = this . props . params ;
2019-07-02 08:10:25 +01:00
2019-07-16 23:42:26 +01:00
if ( typeof group === 'undefined' || ! relationships ) {
2019-07-15 14:47:05 +01:00
return (
< Column >
< LoadingIndicator / >
< / C o l u m n >
) ;
} else if ( group === false ) {
return (
< Column >
< MissingIndicator / >
< / C o l u m n >
) ;
}
2019-07-02 08:10:25 +01:00
2019-07-15 14:47:05 +01:00
return (
< div >
2019-07-16 23:42:26 +01:00
{ relationships . get ( 'member' ) && (
2019-07-15 14:47:05 +01:00
< div className = 'timeline-compose-block' >
< div className = 'timeline-compose-block__avatar' >
< Avatar account = { account } size = { 46 } / >
< / d i v >
< ComposeFormContainer group = { group } shouldCondense = { true } autoFocus = { false } / >
< / d i v >
) }
2019-07-02 08:10:25 +01:00
2019-07-16 12:29:38 +01:00
< div className = 'group__feed' >
2019-08-09 01:41:56 +01:00
< div className = "column-header__wrapper" >
< h1 className = "column-header" >
< Link to = { ` /groups/ ${ id } ` } className = { classNames ( 'btn grouped active' ) } >
{ intl . formatMessage ( messages . tabLatest ) }
< / L i n k >
2019-08-09 03:57:12 +01:00
< div className = 'column-header__buttons' >
< button
className = { classNames ( 'column-header__button' , { 'active' : ! collapsed } ) }
title = { intl . formatMessage ( collapsed ? messages . show : messages . hide ) }
aria - label = { intl . formatMessage ( collapsed ? messages . show : messages . hide ) }
aria - pressed = { collapsed ? 'false' : 'true' }
onClick = { this . handleToggleClick }
> < Icon id = 'sliders' / > < / b u t t o n >
< / d i v >
2019-08-09 01:41:56 +01:00
< / h 1 >
2019-08-09 03:57:12 +01:00
{ ! collapsed && < div className = 'column-header__collapsible' >
< div className = 'column-header__collapsible-inner' >
< div className = 'column-header__collapsible__extra' >
< ColumnSettingsContainer / >
< / d i v >
< / d i v >
< / d i v > }
2019-08-09 01:41:56 +01:00
< / d i v >
2019-07-16 12:29:38 +01:00
< StatusListContainer
alwaysPrepend
scrollKey = { ` group_timeline- ${ columnId } ` }
timelineId = { ` group: ${ id } ` }
onLoadMore = { this . handleLoadMore }
2019-07-26 19:28:26 +01:00
group = { group }
2019-07-16 23:25:23 +01:00
withGroupAdmin = { relationships && relationships . get ( 'admin' ) }
2019-07-16 12:29:38 +01:00
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.' / > }
/ >
< / d i v >
2019-07-15 14:47:05 +01:00
< / d i v >
) ;
}
2019-07-15 17:08:36 +01:00
}