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 ColumnHeader from '../../components/column_header'; import { expandCommunityTimeline } from '../../actions/timelines'; import ColumnSettingsContainer from './containers/column_settings_container'; import { connectCommunityStream } from '../../actions/streaming'; const messages = defineMessages({ title: { id: 'column.community', defaultMessage: 'Local timeline' }, }); const mapStateToProps = (state, { onlyMedia, columnId }) => { const uuid = columnId; const columns = state.getIn(['settings', 'columns']); const index = columns.findIndex(c => c.get('uuid') === uuid); return { hasUnread: state.getIn(['timelines', `community${onlyMedia ? ':media' : ''}`, 'unread']) > 0, onlyMedia: (columnId && index >= 0) ? columns.get(index).getIn(['params', 'other', '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, columnId: PropTypes.string, 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, columnId, onlyMedia } = this.props; return ( } /> ); } }