102 lines
3.0 KiB
JavaScript
102 lines
3.0 KiB
JavaScript
|
import React from 'react';
|
||
|
import { connect } from 'react-redux';
|
||
|
import { expandHomeTimeline } from '../../actions/timelines';
|
||
|
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 { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
||
|
import ColumnSettingsContainer from './containers/column_settings_container';
|
||
|
import { Link } from 'react-router-dom';
|
||
|
import { me } from '../../initial_state';
|
||
|
import ComposeFormContainer from '../compose/containers/compose_form_container';
|
||
|
import Avatar from '../../components/avatar';
|
||
|
|
||
|
const messages = defineMessages({
|
||
|
title: { id: 'column.home', defaultMessage: 'Home' },
|
||
|
});
|
||
|
|
||
|
const mapStateToProps = state => ({
|
||
|
hasUnread: state.getIn(['timelines', 'home', 'unread']) > 0,
|
||
|
isPartial: state.getIn(['timelines', 'home', 'isPartial']),
|
||
|
account: state.getIn(['accounts', me]),
|
||
|
});
|
||
|
|
||
|
export default @connect(mapStateToProps)
|
||
|
@injectIntl
|
||
|
class HomeTimeline extends React.PureComponent {
|
||
|
|
||
|
static propTypes = {
|
||
|
dispatch: PropTypes.func.isRequired,
|
||
|
intl: PropTypes.object.isRequired,
|
||
|
hasUnread: PropTypes.bool,
|
||
|
isPartial: PropTypes.bool,
|
||
|
columnId: PropTypes.string,
|
||
|
};
|
||
|
|
||
|
handleLoadMore = maxId => {
|
||
|
this.props.dispatch(expandHomeTimeline({ maxId }));
|
||
|
}
|
||
|
|
||
|
componentDidMount () {
|
||
|
this._checkIfReloadNeeded(false, this.props.isPartial);
|
||
|
}
|
||
|
|
||
|
componentDidUpdate (prevProps) {
|
||
|
this._checkIfReloadNeeded(prevProps.isPartial, this.props.isPartial);
|
||
|
}
|
||
|
|
||
|
componentWillUnmount () {
|
||
|
this._stopPolling();
|
||
|
}
|
||
|
|
||
|
_checkIfReloadNeeded (wasPartial, isPartial) {
|
||
|
const { dispatch } = this.props;
|
||
|
|
||
|
if (wasPartial === isPartial) {
|
||
|
return;
|
||
|
} else if (!wasPartial && isPartial) {
|
||
|
this.polling = setInterval(() => {
|
||
|
dispatch(expandHomeTimeline());
|
||
|
}, 3000);
|
||
|
} else if (wasPartial && !isPartial) {
|
||
|
this._stopPolling();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
_stopPolling () {
|
||
|
if (this.polling) {
|
||
|
clearInterval(this.polling);
|
||
|
this.polling = null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
render () {
|
||
|
const { intl, hasUnread, columnId, account } = this.props;
|
||
|
|
||
|
return (
|
||
|
<Column label={intl.formatMessage(messages.title)}>
|
||
|
|
||
|
<div className='timeline-compose-block'>
|
||
|
<div className='timeline-compose-block__avatar'>
|
||
|
<Avatar account={account} size={46} />
|
||
|
</div>
|
||
|
<ComposeFormContainer shouldCondense={true} autoFocus={false}/>
|
||
|
</div>
|
||
|
|
||
|
<ColumnHeader icon='home' active={hasUnread} title={intl.formatMessage(messages.title)}>
|
||
|
<ColumnSettingsContainer />
|
||
|
</ColumnHeader>
|
||
|
|
||
|
<StatusListContainer
|
||
|
scrollKey={`home_timeline-${columnId}`}
|
||
|
onLoadMore={this.handleLoadMore}
|
||
|
timelineId='home'
|
||
|
emptyMessage={<FormattedMessage id='empty_column.home' defaultMessage='Your home timeline is empty. Start following other users to recieve their content here.'/>}
|
||
|
/>
|
||
|
</Column>
|
||
|
);
|
||
|
}
|
||
|
|
||
|
}
|