0
0
Fork 0

Allow clients to fetch statuses made while they were offline (#6876)

This commit is contained in:
Akihiko Odaki 2018-03-24 23:25:15 +09:00 committed by Eugen Rochko
parent 59657e24b9
commit 9a1a55ce52
22 changed files with 191 additions and 259 deletions

View file

@ -3,7 +3,7 @@ import { connect } from 'react-redux';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';
import { fetchAccount } from '../../actions/accounts';
import { refreshAccountMediaTimeline, expandAccountMediaTimeline } from '../../actions/timelines';
import { expandAccountMediaTimeline } from '../../actions/timelines';
import LoadingIndicator from '../../components/loading_indicator';
import Column from '../ui/components/column';
import ColumnBackButton from '../../components/column_back_button';
@ -17,9 +17,31 @@ import LoadMore from '../../components/load_more';
const mapStateToProps = (state, props) => ({
medias: getAccountGallery(state, props.params.accountId),
isLoading: state.getIn(['timelines', `account:${props.params.accountId}:media`, 'isLoading']),
hasMore: !!state.getIn(['timelines', `account:${props.params.accountId}:media`, 'next']),
hasMore: state.getIn(['timelines', `account:${props.params.accountId}:media`, 'hasMore']),
});
class LoadMoreMedia extends ImmutablePureComponent {
static propTypes = {
maxId: PropTypes.string,
onLoadMore: PropTypes.func.isRequired,
};
handleLoadMore = () => {
this.props.onLoadMore(this.props.maxId);
}
render () {
return (
<LoadMore
disabled={this.props.disabled}
onLoadMore={this.handleLoadMore}
/>
);
}
}
@connect(mapStateToProps)
export default class AccountGallery extends ImmutablePureComponent {
@ -33,19 +55,19 @@ export default class AccountGallery extends ImmutablePureComponent {
componentDidMount () {
this.props.dispatch(fetchAccount(this.props.params.accountId));
this.props.dispatch(refreshAccountMediaTimeline(this.props.params.accountId));
this.props.dispatch(expandAccountMediaTimeline(this.props.params.accountId));
}
componentWillReceiveProps (nextProps) {
if (nextProps.params.accountId !== this.props.params.accountId && nextProps.params.accountId) {
this.props.dispatch(fetchAccount(nextProps.params.accountId));
this.props.dispatch(refreshAccountMediaTimeline(this.props.params.accountId));
this.props.dispatch(expandAccountMediaTimeline(this.props.params.accountId));
}
}
handleScrollToBottom = () => {
if (this.props.hasMore) {
this.props.dispatch(expandAccountMediaTimeline(this.props.params.accountId));
this.handleLoadMore(this.props.medias.last().get('id'));
}
}
@ -58,7 +80,11 @@ export default class AccountGallery extends ImmutablePureComponent {
}
}
handleLoadMore = (e) => {
handleLoadMore = maxId => {
this.props.dispatch(expandAccountMediaTimeline(this.props.params.accountId, { maxId }));
};
handleLoadOlder = (e) => {
e.preventDefault();
this.handleScrollToBottom();
}
@ -66,7 +92,7 @@ export default class AccountGallery extends ImmutablePureComponent {
render () {
const { medias, isLoading, hasMore } = this.props;
let loadMore = null;
let loadOlder = null;
if (!medias && isLoading) {
return (
@ -77,7 +103,7 @@ export default class AccountGallery extends ImmutablePureComponent {
}
if (!isLoading && medias.size > 0 && hasMore) {
loadMore = <LoadMore onClick={this.handleLoadMore} />;
loadOlder = <LoadMore onClick={this.handleLoadOlder} />;
}
return (
@ -89,13 +115,18 @@ export default class AccountGallery extends ImmutablePureComponent {
<HeaderContainer accountId={this.props.params.accountId} />
<div className='account-gallery__container'>
{medias.map(media => (
{medias.map((media, index) => media === null ? (
<LoadMoreMedia
key={'more:' + medias.getIn(index + 1, 'id')}
maxId={index > 0 ? medias.getIn(index - 1, 'id') : null}
/>
) : (
<MediaItem
key={media.get('id')}
media={media}
/>
))}
{loadMore}
{loadOlder}
</div>
</div>
</ScrollContainer>