mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-11 21:27:05 +00:00
fixes #1078
This commit is contained in:
parent
8148a2f8fe
commit
88fca500f1
1 changed files with 14 additions and 40 deletions
|
|
@ -20,7 +20,6 @@ const Settings = () => {
|
||||||
const profile = useProfile();
|
const profile = useProfile();
|
||||||
const platform = usePlatform();
|
const platform = usePlatform();
|
||||||
const streamingServer = useStreamingServer();
|
const streamingServer = useStreamingServer();
|
||||||
const isScrollingRef = useRef(false);
|
|
||||||
|
|
||||||
const sectionsContainerRef = useRef<HTMLDivElement>(null);
|
const sectionsContainerRef = useRef<HTMLDivElement>(null);
|
||||||
const generalSectionRef = useRef<HTMLDivElement>(null);
|
const generalSectionRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
@ -38,51 +37,26 @@ const Settings = () => {
|
||||||
const [selectedSectionId, setSelectedSectionId] = useState(SECTIONS.GENERAL);
|
const [selectedSectionId, setSelectedSectionId] = useState(SECTIONS.GENERAL);
|
||||||
|
|
||||||
const updateSelectedSectionId = useCallback(() => {
|
const updateSelectedSectionId = useCallback(() => {
|
||||||
if (isScrollingRef.current) return;
|
|
||||||
|
|
||||||
const container = sectionsContainerRef.current;
|
const container = sectionsContainerRef.current;
|
||||||
if (!container) return;
|
for (const section of sections) {
|
||||||
|
const sectionContainer = section.ref.current;
|
||||||
const containerRect = container.getBoundingClientRect();
|
if (sectionContainer && (sectionContainer.offsetTop + container!.offsetTop) < container!.scrollTop + 50) {
|
||||||
const tolerance = 20;
|
setSelectedSectionId(section.id);
|
||||||
|
|
||||||
if (container.scrollTop + container.clientHeight >= container.scrollHeight - 50) {
|
|
||||||
setSelectedSectionId(sections[sections.length - 1].id);
|
|
||||||
} else {
|
|
||||||
for (let i = sections.length - 1; i >= 0; i--) {
|
|
||||||
const section = sections[i].ref.current;
|
|
||||||
if (section) {
|
|
||||||
const sectionRect = section.getBoundingClientRect();
|
|
||||||
if (sectionRect.top <= containerRect.top + tolerance) {
|
|
||||||
setSelectedSectionId(sections[i].id);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [sections]);
|
}, []);
|
||||||
|
|
||||||
const onMenuSelect = useCallback((event: React.MouseEvent<HTMLDivElement>) => {
|
const onMenuSelect = useCallback((event: React.MouseEvent<HTMLDivElement>) => {
|
||||||
const sectionId = event.currentTarget.dataset.section;
|
const section = sections.find((section) => {
|
||||||
const section = sections.find((s) => s.id === sectionId);
|
return section.id === event.currentTarget.dataset.section;
|
||||||
|
});
|
||||||
|
|
||||||
const container = sectionsContainerRef.current;
|
const container = sectionsContainerRef.current;
|
||||||
|
section && container!.scrollTo({
|
||||||
if (section && section.ref.current && container) {
|
top: section.ref.current!.offsetTop - container!.offsetTop,
|
||||||
isScrollingRef.current = true;
|
behavior: 'smooth'
|
||||||
setSelectedSectionId(section.id);
|
});
|
||||||
|
}, []);
|
||||||
const top = section.ref.current.getBoundingClientRect().top - container.getBoundingClientRect().top + container.scrollTop;
|
|
||||||
|
|
||||||
container.scrollTo({
|
|
||||||
top,
|
|
||||||
behavior: 'smooth'
|
|
||||||
});
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
isScrollingRef.current = false;
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
}, [sections]);
|
|
||||||
|
|
||||||
const onContainerScroll = useCallback(throttle(() => {
|
const onContainerScroll = useCallback(throttle(() => {
|
||||||
updateSelectedSectionId();
|
updateSelectedSectionId();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue