import HeaderContainer from '../account_timeline/containers/header_container';
import { FormattedMessage } from 'react-intl';
import { ScrollContainer } from 'react-router-scroll';
+import LoadMore from '../../components/load_more';
const mapStateToProps = (state, props) => ({
medias: getAccountGallery(state, Number(props.params.accountId)),
}
}
+ handleScrollToBottom = () => {
+ if (this.props.hasMore) {
+ this.props.dispatch(expandAccountMediaTimeline(Number(this.props.params.accountId)));
+ }
+ }
+
handleScroll = (e) => {
const { scrollTop, scrollHeight, clientHeight } = e.target;
+ const offset = scrollHeight - scrollTop - clientHeight;
- if (scrollTop === scrollHeight - clientHeight) {
- this.props.dispatch(expandAccountMediaTimeline(Number(this.props.params.accountId)));
+ if (150 > offset && !this.props.isLoading) {
+ this.handleScrollToBottom();
}
}
+ handleLoadMore = (e) => {
+ e.preventDefault();
+ this.handleScrollToBottom();
+ }
+
render () {
- const { medias, autoPlayGif, isLoading } = this.props;
+ const { medias, autoPlayGif, isLoading, hasMore } = this.props;
+
+ let loadMore = null;
if (!medias && isLoading) {
return (
);
}
+ if (!isLoading && medias.size > 0 && hasMore) {
+ loadMore = <LoadMore onClick={this.handleLoadMore} />;
+ }
+
return (
<Column>
<ColumnBackButton />
autoPlayGif={autoPlayGif}
/>
)}
+ {loadMore}
</div>
</div>
</ScrollContainer>
.update('items', Immutable.List(), list => (replace ? ids : ids.concat(list))));
};
-const normalizeAccountMediaTimeline = (state, accountId, statuses, next) => {
+const normalizeAccountMediaTimeline = (state, accountId, statuses) => {
let ids = Immutable.List();
statuses.forEach((status, i) => {
return state.updateIn(['accounts_media_timelines', accountId], Immutable.Map(), map => map
.set('isLoading', false)
- .set('next', next)
+ .set('next', true)
.update('items', Immutable.List(), list => ids.concat(list)));
};
case ACCOUNT_MEDIA_TIMELINE_EXPAND_FAIL:
return state.updateIn(['accounts_media_timelines', action.id], Immutable.Map(), map => map.set('isLoading', false));
case ACCOUNT_MEDIA_TIMELINE_FETCH_SUCCESS:
- return normalizeAccountMediaTimeline(state, action.id, Immutable.fromJS(action.statuses), action.next);
+ return normalizeAccountMediaTimeline(state, action.id, Immutable.fromJS(action.statuses));
case ACCOUNT_MEDIA_TIMELINE_EXPAND_SUCCESS:
return appendNormalizedAccountMediaTimeline(state, action.id, Immutable.fromJS(action.statuses), action.next);
case ACCOUNT_BLOCK_SUCCESS: