import React from 'react'; import { connect } from 'react-redux'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import PropTypes from 'prop-types'; import StatusListContainer from '../ui/containers/status_list_container'; import Column from '../../components/column'; import { expandCommunityTimeline } from '../../actions/timelines'; import ColumnSettingsContainer from './containers/column_settings_container'; import { connectCommunityStream } from '../../actions/streaming'; import HomeColumnHeader from '../../components/home_column_header'; const messages = defineMessages({ title: { id: 'column.community', defaultMessage: 'Local timeline' }, }); const mapStateToProps = (state, { onlyMedia }) => ({ hasUnread: state.getIn(['timelines', `community${onlyMedia ? ':media' : ''}`, 'unread']) > 0, onlyMedia: state.getIn(['settings', 'community', 'other', 'onlyMedia']), }); export default @connect(mapStateToProps) @injectIntl class CommunityTimeline extends React.PureComponent { static contextTypes = { router: PropTypes.object, }; static defaultProps = { onlyMedia: false, }; static propTypes = { dispatch: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, hasUnread: PropTypes.bool, onlyMedia: PropTypes.bool, }; componentDidMount () { const { dispatch, onlyMedia } = this.props; dispatch(expandCommunityTimeline({ onlyMedia })); this.disconnect = dispatch(connectCommunityStream({ onlyMedia })); } componentDidUpdate (prevProps) { if (prevProps.onlyMedia !== this.props.onlyMedia) { const { dispatch, onlyMedia } = this.props; this.disconnect(); dispatch(expandCommunityTimeline({ onlyMedia })); this.disconnect = dispatch(connectCommunityStream({ onlyMedia })); } } componentWillUnmount () { if (this.disconnect) { this.disconnect(); this.disconnect = null; } } handleLoadMore = maxId => { const { dispatch, onlyMedia } = this.props; dispatch(expandCommunityTimeline({ maxId, onlyMedia })); } render () { const { intl, hasUnread, onlyMedia } = this.props; return ( } /> ); } }