2017-07-11 22:27:59 +09:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import PropTypes from 'prop-types';
|
2019-03-13 01:34:00 +09:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import { expandPublicTimeline, expandCommunityTimeline } from 'flavours/glitch/actions/timelines';
|
|
|
|
import { connectPublicStream, connectCommunityStream } from 'flavours/glitch/actions/streaming';
|
|
|
|
import Masonry from 'react-masonry-infinite';
|
|
|
|
import { List as ImmutableList, Map as ImmutableMap } from 'immutable';
|
|
|
|
import DetailedStatusContainer from 'flavours/glitch/features/status/containers/detailed_status_container';
|
|
|
|
import { debounce } from 'lodash';
|
|
|
|
import LoadingIndicator from 'flavours/glitch/components/loading_indicator';
|
2017-07-11 22:27:59 +09:00
|
|
|
|
2019-03-13 01:34:00 +09:00
|
|
|
const mapStateToProps = (state, { local }) => {
|
|
|
|
const timeline = state.getIn(['timelines', local ? 'community' : 'public'], ImmutableMap());
|
2017-07-11 22:27:59 +09:00
|
|
|
|
2019-03-13 01:34:00 +09:00
|
|
|
return {
|
|
|
|
statusIds: timeline.get('items', ImmutableList()),
|
|
|
|
isLoading: timeline.get('isLoading', false),
|
|
|
|
hasMore: timeline.get('hasMore', false),
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export default @connect(mapStateToProps)
|
|
|
|
class PublicTimeline extends React.PureComponent {
|
2017-07-11 22:27:59 +09:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
2019-03-13 01:34:00 +09:00
|
|
|
statusIds: ImmutablePropTypes.list.isRequired,
|
|
|
|
isLoading: PropTypes.bool.isRequired,
|
|
|
|
hasMore: PropTypes.bool.isRequired,
|
|
|
|
local: PropTypes.bool,
|
2017-07-11 22:27:59 +09:00
|
|
|
};
|
|
|
|
|
2019-03-13 01:34:00 +09:00
|
|
|
componentDidMount () {
|
|
|
|
this._connect();
|
2017-07-11 22:27:59 +09:00
|
|
|
}
|
|
|
|
|
2019-03-13 01:34:00 +09:00
|
|
|
componentDidUpdate (prevProps) {
|
|
|
|
if (prevProps.local !== this.props.local) {
|
|
|
|
this._disconnect();
|
|
|
|
this._connect();
|
|
|
|
}
|
2017-07-11 22:27:59 +09:00
|
|
|
}
|
|
|
|
|
2019-03-13 01:34:00 +09:00
|
|
|
componentWillUnmount () {
|
|
|
|
this._disconnect();
|
2017-07-11 22:27:59 +09:00
|
|
|
}
|
|
|
|
|
2019-03-13 01:34:00 +09:00
|
|
|
_connect () {
|
|
|
|
const { dispatch, local } = this.props;
|
|
|
|
|
|
|
|
dispatch(local ? expandCommunityTimeline() : expandPublicTimeline());
|
|
|
|
this.disconnect = dispatch(local ? connectCommunityStream() : connectPublicStream());
|
|
|
|
}
|
|
|
|
|
|
|
|
_disconnect () {
|
2018-05-28 00:10:48 +09:00
|
|
|
if (this.disconnect) {
|
|
|
|
this.disconnect();
|
|
|
|
this.disconnect = null;
|
2017-07-11 22:27:59 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-28 02:10:37 +09:00
|
|
|
handleLoadMore = maxId => {
|
2019-03-13 01:34:00 +09:00
|
|
|
const { dispatch, local } = this.props;
|
|
|
|
dispatch(local ? expandCommunityTimeline({ maxId }) : expandPublicTimeline({ maxId }));
|
2017-07-11 22:27:59 +09:00
|
|
|
}
|
|
|
|
|
2019-03-13 01:34:00 +09:00
|
|
|
setRef = c => {
|
|
|
|
this.masonry = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
handleHeightChange = debounce(() => {
|
|
|
|
if (!this.masonry) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.masonry.forcePack();
|
|
|
|
}, 50)
|
|
|
|
|
2017-07-11 22:27:59 +09:00
|
|
|
render () {
|
2019-03-13 01:34:00 +09:00
|
|
|
const { statusIds, hasMore, isLoading } = this.props;
|
|
|
|
|
|
|
|
const sizes = [
|
|
|
|
{ columns: 1, gutter: 0 },
|
|
|
|
{ mq: '415px', columns: 1, gutter: 10 },
|
|
|
|
{ mq: '640px', columns: 2, gutter: 10 },
|
|
|
|
{ mq: '960px', columns: 3, gutter: 10 },
|
|
|
|
{ mq: '1255px', columns: 3, gutter: 10 },
|
|
|
|
];
|
|
|
|
|
|
|
|
const loader = (isLoading && statusIds.isEmpty()) ? <LoadingIndicator key={0} /> : undefined;
|
2017-07-11 22:27:59 +09:00
|
|
|
|
|
|
|
return (
|
2019-03-13 01:34:00 +09:00
|
|
|
<Masonry ref={this.setRef} className='statuses-grid' hasMore={hasMore} loadMore={this.handleLoadMore} sizes={sizes} loader={loader}>
|
|
|
|
{statusIds.map(statusId => (
|
|
|
|
<div className='statuses-grid__item' key={statusId}>
|
|
|
|
<DetailedStatusContainer
|
|
|
|
id={statusId}
|
|
|
|
compact
|
|
|
|
measureHeight
|
|
|
|
onHeightChange={this.handleHeightChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)).toArray()}
|
|
|
|
</Masonry>
|
2017-07-11 22:27:59 +09:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|