mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-25 17:44:14 -05:00
376e524278
Port front-end changes from f52c988e12
to glitch-soc
Signed-off-by: Thibaut Girka <thib@sitedethib.com>
130 lines
3.8 KiB
JavaScript
130 lines
3.8 KiB
JavaScript
import React from 'react';
|
|
import { connect } from 'react-redux';
|
|
import { expandHomeTimeline } from 'flavours/glitch/actions/timelines';
|
|
import PropTypes from 'prop-types';
|
|
import StatusListContainer from 'flavours/glitch/features/ui/containers/status_list_container';
|
|
import Column from 'flavours/glitch/components/column';
|
|
import ColumnHeader from 'flavours/glitch/components/column_header';
|
|
import { addColumn, removeColumn, moveColumn } from 'flavours/glitch/actions/columns';
|
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
|
|
import ColumnSettingsContainer from './containers/column_settings_container';
|
|
import { Link } from 'react-router-dom';
|
|
import AnnouncementsContainer from 'flavours/glitch/features/getting_started/containers/announcements_container';
|
|
|
|
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']),
|
|
});
|
|
|
|
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,
|
|
multiColumn: PropTypes.bool,
|
|
};
|
|
|
|
handlePin = () => {
|
|
const { columnId, dispatch } = this.props;
|
|
|
|
if (columnId) {
|
|
dispatch(removeColumn(columnId));
|
|
} else {
|
|
dispatch(addColumn('HOME', {}));
|
|
}
|
|
}
|
|
|
|
handleMove = (dir) => {
|
|
const { columnId, dispatch } = this.props;
|
|
dispatch(moveColumn(columnId, dir));
|
|
}
|
|
|
|
handleHeaderClick = () => {
|
|
this.column.scrollTop();
|
|
}
|
|
|
|
setRef = c => {
|
|
this.column = c;
|
|
}
|
|
|
|
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, multiColumn } = this.props;
|
|
const pinned = !!columnId;
|
|
|
|
return (
|
|
<Column bindToDocument={!multiColumn} ref={this.setRef} name='home' label={intl.formatMessage(messages.title)}>
|
|
<ColumnHeader
|
|
icon='home'
|
|
active={hasUnread}
|
|
title={intl.formatMessage(messages.title)}
|
|
onPin={this.handlePin}
|
|
onMove={this.handleMove}
|
|
onClick={this.handleHeaderClick}
|
|
pinned={pinned}
|
|
multiColumn={multiColumn}
|
|
>
|
|
<ColumnSettingsContainer />
|
|
</ColumnHeader>
|
|
|
|
<StatusListContainer
|
|
prepend={<AnnouncementsContainer />}
|
|
alwaysPrepend
|
|
trackScroll={!pinned}
|
|
scrollKey={`home_timeline-${columnId}`}
|
|
onLoadMore={this.handleLoadMore}
|
|
timelineId='home'
|
|
emptyMessage={<FormattedMessage id='empty_column.home' defaultMessage='Your home timeline is empty! Visit {public} or use search to get started and meet other users.' values={{ public: <Link to='/timelines/public'><FormattedMessage id='empty_column.home.public_timeline' defaultMessage='the public timeline' /></Link> }} />}
|
|
bindToDocument={!multiColumn}
|
|
/>
|
|
</Column>
|
|
);
|
|
}
|
|
|
|
}
|