Skip to content

Commit 67d78fa

Browse files
committed
fix: repositionning scroll
1 parent 4b6a5d3 commit 67d78fa

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

package-lock.json

+33-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"@testing-library/react": "^12.0.0",
7575
"@testing-library/user-event": "^13.1.9",
7676
"@types/jest": "^26.0.24",
77+
"@types/jquery": "^3.5.6",
7778
"@types/lodash": "^4.14.172",
7879
"@types/node": "^16.0.1",
7980
"@types/react": "^17.0.14",

src/components/VirtualScroller.tsx

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { debounce } from "lodash";
2-
import { FC, ReactNode, useCallback, useEffect, useRef, useState } from "react";
2+
import React, {
3+
FC,
4+
ReactNode,
5+
useCallback,
6+
useEffect,
7+
useRef,
8+
useState,
9+
} from "react";
10+
import ReactDOM from "react-dom";
311

412
export interface VirtualScrollerProps {
513
data: (...arg: any) => [];
@@ -31,6 +39,7 @@ export const VirtualScroll: FC<VirtualScrollerProps> = ({
3139
const numberItem = useRef(0);
3240
numberItem.current = nbItems;
3341

42+
//@ts-ignore
3443
const fctData = useRef((...args: any[]) => {});
3544
fctData.current = data;
3645

@@ -76,19 +85,27 @@ export const VirtualScroll: FC<VirtualScrollerProps> = ({
7685
const index =
7786
minIndex + Math.floor((scrollTop - toleranceHeight) / itemHeight);
7887
setMargin(index);
88+
7989
const res = new Array(amount);
8090
for (let i = 0; i < amount; i++) {
8191
res[i] = Skeleton;
8292
}
8393
setRes(res);
94+
8495
debounceGenData(index);
8596
};
8697

8798
useEffect(() => {
8899
if (!initialPosition) {
89100
genData(0);
101+
} else {
102+
var scrollPos = initialPosition;
103+
if (initialPosition > nbItems * 65) {
104+
scrollPos = 0;
105+
}
106+
$(".scroller").scrollTop(scrollPos);
90107
}
91-
});
108+
}, [data]);
92109

93110
if (loading) {
94111
return <>{LoadingSplash}</>;
@@ -101,6 +118,7 @@ export const VirtualScroll: FC<VirtualScrollerProps> = ({
101118
overflowY: "auto",
102119
overflowAnchor: "none",
103120
}}
121+
className="scroller"
104122
>
105123
<div style={{ height: topPaddingHeight }} id="becaglacon" />
106124
{res}

0 commit comments

Comments
 (0)