Skip to content

Commit

Permalink
Fix timeline pagination in the WebUI (#9516)
Browse files Browse the repository at this point in the history
The `hasMore` property of timelines in redux store was set whenever an API
request returned only one page of results, *even* if the query only requested
newer statuses (using `since_id`), causing `hasMore` to be incorrectly set to
false whenever fetching new toots in a timeline, which happens each time
an account's timeline or media gallery is visited.
  • Loading branch information
ClearlyClaire authored and Gargron committed Dec 14, 2018
1 parent 6eece70 commit f20c0b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions app/javascript/mastodon/actions/timelines.js
Expand Up @@ -74,12 +74,14 @@ export function expandTimeline(timelineId, path, params = {}, done = noOp) {
params.since_id = timeline.getIn(['items', 0]);
}

const isLoadingRecent = !!params.since_id;

dispatch(expandTimelineRequest(timelineId, isLoadingMore));

api(getState).get(path, { params }).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');
dispatch(importFetchedStatuses(response.data));
dispatch(expandTimelineSuccess(timelineId, response.data, next ? next.uri : null, response.code === 206, isLoadingMore));
dispatch(expandTimelineSuccess(timelineId, response.data, next ? next.uri : null, response.code === 206, isLoadingRecent, isLoadingMore));
done();
}).catch(error => {
dispatch(expandTimelineFail(timelineId, error, isLoadingMore));
Expand Down Expand Up @@ -112,13 +114,14 @@ export function expandTimelineRequest(timeline, isLoadingMore) {
};
};

export function expandTimelineSuccess(timeline, statuses, next, partial, isLoadingMore) {
export function expandTimelineSuccess(timeline, statuses, next, partial, isLoadingRecent, isLoadingMore) {
return {
type: TIMELINE_EXPAND_SUCCESS,
timeline,
statuses,
next,
partial,
isLoadingRecent,
skipLoading: !isLoadingMore,
};
};
Expand Down
6 changes: 3 additions & 3 deletions app/javascript/mastodon/reducers/timelines.js
Expand Up @@ -26,10 +26,10 @@ const initialTimeline = ImmutableMap({
items: ImmutableList(),
});

const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial) => {
const expandNormalizedTimeline = (state, timeline, statuses, next, isPartial, isLoadingRecent) => {
return state.update(timeline, initialTimeline, map => map.withMutations(mMap => {
mMap.set('isLoading', false);
if (!next) mMap.set('hasMore', false);
if (!next && !isLoadingRecent) mMap.set('hasMore', false);

if (!statuses.isEmpty()) {
mMap.update('items', ImmutableList(), oldIds => {
Expand Down Expand Up @@ -126,7 +126,7 @@ export default function timelines(state = initialState, action) {
case TIMELINE_EXPAND_FAIL:
return state.update(action.timeline, initialTimeline, map => map.set('isLoading', false));
case TIMELINE_EXPAND_SUCCESS:
return expandNormalizedTimeline(state, action.timeline, fromJS(action.statuses), action.next, action.partial);
return expandNormalizedTimeline(state, action.timeline, fromJS(action.statuses), action.next, action.partial, action.isLoadingRecent);
case TIMELINE_UPDATE:
return updateTimeline(state, action.timeline, fromJS(action.status));
case TIMELINE_DELETE:
Expand Down

0 comments on commit f20c0b8

Please sign in to comment.