Skip to content

Commit

Permalink
fix(frontend): infinite scrolling list fix & speedup
Browse files Browse the repository at this point in the history
  • Loading branch information
thesophiaxu committed Feb 14, 2022
1 parent 3ba52b0 commit bcb568d
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ export const setupInfiniteScrolling = (
};

const onUserNext = (updating: boolean) => {
const [subsHead, chunksHead] = [states.currentSubs.length / chunk, states.chunks.length];
if (subsHead < chunksHead) {
const [subsHead, chunksHead] = [Math.floor(states.currentSubs.length / chunk), states.chunks.length];
if (updating || subsHead < chunksHead) {
if (updating) {
states.currentSubs = states.currentSubs.filter((el) => uids.includes(el));
states.currentSubs = _.uniq([
...states.currentSubs.filter((el) => uids.includes(el)),
...(states.chunks[0] || []),
]);
} else {
const toSub = states.chunks[subsHead];
states.currentSubs = [...states.currentSubs, ...toSub];
Expand Down

0 comments on commit bcb568d

Please sign in to comment.