[Glitch] Fix timeline pagination in the WebUI
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.remotes/1727458204337373841/tmp_refs/heads/signup-info-prompt
parent
c20c6c2029
commit
132dd28162
|
@ -54,11 +54,13 @@ export function expandTimeline(timelineId, path, params = {}, done = noOp) {
|
||||||
params.since_id = timeline.getIn(['items', 0]);
|
params.since_id = timeline.getIn(['items', 0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isLoadingRecent = !!params.since_id;
|
||||||
|
|
||||||
dispatch(expandTimelineRequest(timelineId, isLoadingMore));
|
dispatch(expandTimelineRequest(timelineId, isLoadingMore));
|
||||||
|
|
||||||
api(getState).get(path, { params }).then(response => {
|
api(getState).get(path, { params }).then(response => {
|
||||||
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
||||||
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();
|
done();
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(expandTimelineFail(timelineId, error, isLoadingMore));
|
dispatch(expandTimelineFail(timelineId, error, isLoadingMore));
|
||||||
|
@ -85,13 +87,14 @@ export function expandTimelineRequest(timeline, isLoadingMore) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function expandTimelineSuccess(timeline, statuses, next, partial, isLoadingMore) {
|
export function expandTimelineSuccess(timeline, statuses, next, partial, isLoadingRecent, isLoadingMore) {
|
||||||
return {
|
return {
|
||||||
type: TIMELINE_EXPAND_SUCCESS,
|
type: TIMELINE_EXPAND_SUCCESS,
|
||||||
timeline,
|
timeline,
|
||||||
statuses,
|
statuses,
|
||||||
next,
|
next,
|
||||||
partial,
|
partial,
|
||||||
|
isLoadingRecent,
|
||||||
skipLoading: !isLoadingMore,
|
skipLoading: !isLoadingMore,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,10 +25,10 @@ const initialTimeline = ImmutableMap({
|
||||||
items: ImmutableList(),
|
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 => {
|
return state.update(timeline, initialTimeline, map => map.withMutations(mMap => {
|
||||||
mMap.set('isLoading', false);
|
mMap.set('isLoading', false);
|
||||||
if (!next) mMap.set('hasMore', false);
|
if (!next && !isLoadingRecent) mMap.set('hasMore', false);
|
||||||
|
|
||||||
if (!statuses.isEmpty()) {
|
if (!statuses.isEmpty()) {
|
||||||
mMap.update('items', ImmutableList(), oldIds => {
|
mMap.update('items', ImmutableList(), oldIds => {
|
||||||
|
@ -116,7 +116,7 @@ export default function timelines(state = initialState, action) {
|
||||||
case TIMELINE_EXPAND_FAIL:
|
case TIMELINE_EXPAND_FAIL:
|
||||||
return state.update(action.timeline, initialTimeline, map => map.set('isLoading', false));
|
return state.update(action.timeline, initialTimeline, map => map.set('isLoading', false));
|
||||||
case TIMELINE_EXPAND_SUCCESS:
|
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:
|
case TIMELINE_UPDATE:
|
||||||
return updateTimeline(state, action.timeline, fromJS(action.status));
|
return updateTimeline(state, action.timeline, fromJS(action.status));
|
||||||
case TIMELINE_DELETE:
|
case TIMELINE_DELETE:
|
||||||
|
|
Loading…
Reference in New Issue