Skip to content

Commit

Permalink
WIP try fix TL jump on back from status
Browse files Browse the repository at this point in the history
  • Loading branch information
Cl0v1s authored and null2264 committed Oct 7, 2023
1 parent 54df35f commit 4d19806
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
1 change: 1 addition & 0 deletions app/soapbox/actions/timelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ const expandTimelineSuccess = (
partial,
isLoadingRecent,
skipLoading: !isLoadingMore,
isLoadingMore,
});

const expandTimelineFail = (timeline: string, error: AxiosError, isLoadingMore: boolean) => ({
Expand Down
55 changes: 33 additions & 22 deletions app/soapbox/reducers/timelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,34 +96,44 @@ const expandNormalizedTimeline = (
prev: string | undefined,
isPartial: boolean,
isLoadingRecent: boolean,
isLoadingMore: boolean,
) => {
const newIds = getStatusIds(statuses);
let newIds = getStatusIds(statuses);
const unseens = ImmutableOrderedSet<any>();

return state.update(timelineId, TimelineRecord(), timeline => timeline.withMutations(timeline => {
timeline.set('isLoading', false);
timeline.set('loadingFailed', false);
timeline.set('isPartial', isPartial);
timeline.set('next', next);
timeline.set('prev', prev);
return state.withMutations((s: any) => {
s.update(timelineId, TimelineRecord(), (timeline: any) => timeline.withMutations((timeline: any) => {
timeline.set('isLoading', false);
timeline.set('loadingFailed', false);
timeline.set('isPartial', isPartial);

if (!next && !isLoadingRecent) timeline.set('hasMore', false);
if (!next && !isLoadingRecent) timeline.set('hasMore', false);

// Pinned timelines can be replaced entirely
if (timelineId.endsWith(':pinned')) {
timeline.set('items', newIds);
return;
}
// Pinned timelines can be replaced entirely
if (timelineId.endsWith(':pinned')) {
timeline.set('items', newIds);
return;
}

if (!newIds.isEmpty()) {
timeline.update('items', oldIds => {
if (newIds.first() > oldIds.first()!) {
return mergeStatusIds(oldIds, newIds);
} else {
return mergeStatusIds(newIds, oldIds);
if (!newIds.isEmpty()) {
// we need to sort between queue and actual list to avoid
// messing with user position in the timeline by inserting inseen statuses
let unseens = ImmutableOrderedSet<any>();
if (!isLoadingMore && timeline.items.count() > 0) {
unseens = newIds.subtract(timeline.items);
}
});
}
}));
newIds = newIds.subtract(unseens);
timeline.update('items', (oldIds: any) => {
if (newIds.first() > oldIds.first()!) {
return mergeStatusIds(oldIds, newIds);
} else {
return mergeStatusIds(newIds, oldIds);
}
});
}
}));
unseens.forEach((statusId: any) => updateTimelineQueue(s, timelineId, statusId));
});
};

const updateTimeline = (state: State, timelineId: string, statusId: string) => {
Expand Down Expand Up @@ -341,6 +351,7 @@ export default function timelines(state: State = initialState, action: AnyAction
action.prev,
action.partial,
action.isLoadingRecent,
action.isLoadingMore,
);
case TIMELINE_UPDATE:
return updateTimeline(state, action.timeline, action.statusId);
Expand Down

0 comments on commit 4d19806

Please sign in to comment.